| @@ 227-237 (lines=11) @@ | ||
| 224 | * |
|
| 225 | * @return boolean TRUE on sucess, FALSE otherwise |
|
| 226 | */ |
|
| 227 | private function init() |
|
| 228 | { |
|
| 229 | $script = ' |
|
| 230 | if not redis.call("EXISTS", KEYS[1], KEYS[2]) == 2 then |
|
| 231 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 232 | else |
|
| 233 | return 0 |
|
| 234 | end |
|
| 235 | '; |
|
| 236 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 237 | } |
|
| 238 | ||
| 239 | /** |
|
| 240 | * Try to get the lock |
|
| @@ 270-280 (lines=11) @@ | ||
| 267 | * |
|
| 268 | * @return boolean TRUE on success, FALSE otherwise |
|
| 269 | */ |
|
| 270 | private function unlockAndSignal() |
|
| 271 | { |
|
| 272 | $script = ' |
|
| 273 | if redis.call("GET", KEYS[1]) == ARGV[1] and redis.call("DEL", KEYS[1]) == 1 then |
|
| 274 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 275 | else |
|
| 276 | return 0 |
|
| 277 | end |
|
| 278 | '; |
|
| 279 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 280 | } |
|
| 281 | ||
| 282 | } |
|
| 283 | ||