protected function release($key)
{
/*
* Question for Redis: Why do I have to try to delete also keys
* which I haven't acquired? I do observe collisions of the random
* token, which results in releasing the wrong key.
*/
$script = '
if redis.call("get",KEYS[1]) == ARGV[1] then
return redis.call("del",KEYS[1])
else
return 0
end
';
$released = 0;
foreach ($this->redisAPIs as $redis) {
try {
if ($this->evalScript($redis, $script, 1, [$key, $this->token])) {
$released++;
}
} catch (LockReleaseException $e) {
$context = ["key" => $key, "token" => $this->token, "redis" => $this->getRedisIdentifier($redis), "exception" => $e];
$this->logger->warning("Could not unset {key} = {token} at {redis}.", $context);
}
}
return $this->isMajority($released);
}