| @@ 228-238 (lines=11) @@ | ||
| 225 | * |
|
| 226 | * @return boolean TRUE on success, FALSE otherwise |
|
| 227 | */ |
|
| 228 | private function init() |
|
| 229 | { |
|
| 230 | $script = ' |
|
| 231 | if redis.call("EXISTS", KEYS[1], KEYS[2]) == 0 then |
|
| 232 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 233 | else |
|
| 234 | return 0 |
|
| 235 | end |
|
| 236 | '; |
|
| 237 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 238 | } |
|
| 239 | ||
| 240 | /** |
|
| 241 | * Try to get the lock |
|
| @@ 273-283 (lines=11) @@ | ||
| 270 | * |
|
| 271 | * @return boolean TRUE on success, FALSE otherwise |
|
| 272 | */ |
|
| 273 | private function unlockAndSignal() |
|
| 274 | { |
|
| 275 | $script = ' |
|
| 276 | if (redis.call("GET", KEYS[1]) == ARGV[1]) and (redis.call("DEL", KEYS[1]) == 1) then |
|
| 277 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 278 | else |
|
| 279 | return 0 |
|
| 280 | end |
|
| 281 | '; |
|
| 282 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 283 | } |
|
| 284 | ||
| 285 | } |
|
| 286 | ||
| @@ 243-255 (lines=13) @@ | ||
| 240 | * |
|
| 241 | * @return boolean TRUE on success, FALSE otherwise |
|
| 242 | */ |
|
| 243 | private function init() |
|
| 244 | { |
|
| 245 | $script = ' |
|
| 246 | if redis.call("EXISTS", KEYS[1], KEYS[2]) == 0 then |
|
| 247 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 248 | else |
|
| 249 | return 0 |
|
| 250 | end |
|
| 251 | '; |
|
| 252 | $ret = $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 253 | ||
| 254 | return (bool) $ret; |
|
| 255 | } |
|
| 256 | ||
| 257 | /** |
|
| 258 | * Try to get the lock |
|
| @@ 290-300 (lines=11) @@ | ||
| 287 | * |
|
| 288 | * @return boolean TRUE on success, FALSE otherwise |
|
| 289 | */ |
|
| 290 | private function unlockAndSignal() |
|
| 291 | { |
|
| 292 | $script = ' |
|
| 293 | if (redis.call("GET", KEYS[1]) == ARGV[1]) and (redis.call("DEL", KEYS[1]) == 1) then |
|
| 294 | return redis.call("RPUSH", KEYS[2], ARGV[1]) and redis.call("EXPIRE", KEYS[2], ARGV[2]) |
|
| 295 | else |
|
| 296 | return 0 |
|
| 297 | end |
|
| 298 | '; |
|
| 299 | return (bool) $this->redis->eval($script, [$this->name, $this->mutex, $this->value, $this->ttl], 2); |
|
| 300 | } |
|
| 301 | ||
| 302 | } |
|
| 303 | ||