@@ 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 |
|
@@ 269-279 (lines=11) @@ | ||
266 | * |
|
267 | * @return boolean TRUE on success, FALSE otherwise |
|
268 | */ |
|
269 | private function unlockAndSignal() |
|
270 | { |
|
271 | $script = ' |
|
272 | if redis.call("GET", KEYS[1]) == ARGV[1] and redis.call("DEL", KEYS[1]) then |
|
273 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
274 | else |
|
275 | return 0 |
|
276 | end |
|
277 | '; |
|
278 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
279 | } |
|
280 | ||
281 | } |
|
282 |