function RedisStore::save
Overrides PersistingStoreInterface::save
File
-
vendor/
symfony/ lock/ Store/ RedisStore.php, line 48
Class
- RedisStore
- RedisStore is a PersistingStoreInterface implementation using Redis as store engine.
Namespace
Symfony\Component\Lock\StoreCode
public function save(Key $key) : void {
$script = '
local key = KEYS[1]
local uniqueToken = ARGV[2]
local ttl = tonumber(ARGV[3])
-- asserts the KEY is compatible with current version (old Symfony <5.2 BC)
if redis.call("TYPE", key).ok == "string" then
return false
end
' . $this->getNowCode() . '
-- Remove expired values
redis.call("ZREMRANGEBYSCORE", key, "-inf", now)
-- is already acquired
if redis.call("ZSCORE", key, uniqueToken) then
-- is not WRITE lock and cannot be promoted
if not redis.call("ZSCORE", key, "__write__") and redis.call("ZCOUNT", key, "-inf", "+inf") > 1 then
return false
end
elseif redis.call("ZCOUNT", key, "-inf", "+inf") > 0 then
return false
end
redis.call("ZADD", key, now + ttl, uniqueToken)
redis.call("ZADD", key, now + ttl, "__write__")
-- Extend the TTL of the key
local maxExpiration = redis.call("ZREVRANGE", key, 0, 0, "WITHSCORES")[2]
redis.call("PEXPIREAT", key, maxExpiration)
return true
';
$key->reduceLifetime($this->initialTtl);
if (!$this->evaluate($script, (string) $key, [
microtime(true),
$this->getUniqueToken($key),
(int) ceil($this->initialTtl * 1000),
])) {
throw new LockConflictedException();
}
$this->checkNotExpired($key);
}