| @@ 256-266 (lines=11) @@ | ||
| 253 | * |
|
| 254 | * @return boolean TRUE on success, FALSE otherwise |
|
| 255 | */ |
|
| 256 | private function unlockAndSignal() |
|
| 257 | { |
|
| 258 | $script = ' |
|
| 259 | if (redis.call("GET", KEYS[1]) == ARGV[1]) and (redis.call("DEL", KEYS[1]) == 1) then |
|
| 260 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 261 | else |
|
| 262 | return 0 |
|
| 263 | end |
|
| 264 | '; |
|
| 265 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 266 | } |
|
| 267 | ||
| 268 | } |
|
| 269 | ||
| @@ 251-263 (lines=13) @@ | ||
| 248 | * |
|
| 249 | * @return boolean TRUE on success, FALSE otherwise |
|
| 250 | */ |
|
| 251 | private function init() |
|
| 252 | { |
|
| 253 | $script = ' |
|
| 254 | if redis.call("EXISTS", KEYS[1], KEYS[2]) == 0 then |
|
| 255 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 256 | else |
|
| 257 | return 0 |
|
| 258 | end |
|
| 259 | '; |
|
| 260 | $ret = $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 261 | ||
| 262 | return (bool) $ret; |
|
| 263 | } |
|
| 264 | ||
| 265 | /** |
|
| 266 | * Try to get the lock |
|
| @@ 298-308 (lines=11) @@ | ||
| 295 | * |
|
| 296 | * @return boolean TRUE on success, FALSE otherwise |
|
| 297 | */ |
|
| 298 | private function unlockAndSignal() |
|
| 299 | { |
|
| 300 | $script = ' |
|
| 301 | if (redis.call("GET", KEYS[1]) == ARGV[1]) and (redis.call("DEL", KEYS[1]) == 1) then |
|
| 302 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 303 | else |
|
| 304 | return 0 |
|
| 305 | end |
|
| 306 | '; |
|
| 307 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 308 | } |
|
| 309 | ||
| 310 | } |
|
| 311 | ||