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