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