@@ 236-246 (lines=11) @@ | ||
233 | * |
|
234 | * @return boolean TRUE on sucess, FALSE otherwise |
|
235 | */ |
|
236 | private function init() |
|
237 | { |
|
238 | $script = ' |
|
239 | if redis.call("EXISTS", KEYS[1], KEYS[2]) == 0 then |
|
240 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
241 | else |
|
242 | return 0 |
|
243 | end |
|
244 | '; |
|
245 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
246 | } |
|
247 | ||
248 | /** |
|
249 | * Try to get the lock |
|
@@ 280-290 (lines=11) @@ | ||
277 | * |
|
278 | * @return boolean TRUE on success, FALSE otherwise |
|
279 | */ |
|
280 | private function unlockAndSignal() |
|
281 | { |
|
282 | $script = ' |
|
283 | if (redis.call("GET", KEYS[1]) == ARGV[1]) and (redis.call("DEL", KEYS[1]) == 1) then |
|
284 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
285 | else |
|
286 | return 0 |
|
287 | end |
|
288 | '; |
|
289 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
290 | } |
|
291 | ||
292 | } |
|
293 |