改名
This commit is contained in:
@@ -295,12 +295,15 @@ class Redis extends Component
|
|||||||
*/
|
*/
|
||||||
public function lock($key, $timeout = 5)
|
public function lock($key, $timeout = 5)
|
||||||
{
|
{
|
||||||
$redis = $this->proxy();
|
$script = <<<SCRIPT
|
||||||
if (!$redis->setnx($key, 1)) {
|
local _nx = redis.call('setnx',KEYS[1], ARGV[1])
|
||||||
return false;
|
if (_nx ~= 0) then
|
||||||
}
|
redis.call('expire',KEYS[1], ARGV[1])
|
||||||
$redis->expire($key, $timeout);
|
return 1
|
||||||
return true;
|
end
|
||||||
|
return 0
|
||||||
|
SCRIPT;
|
||||||
|
return $this->proxy()->eval($script, [$key, $timeout], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user