Skip to content

Commit b9a1ec4

Browse files
author
Willem Stuursma
committed
Add some typehints and comments to see how it all works
1 parent 815b55b commit b9a1ec4

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/.idea/
12
/composer.lock
23
/vendor/

classes/mutex/PHPRedisMutex.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
class PHPRedisMutex extends RedisMutex
2222
{
23-
2423
/**
2524
* Sets the connected Redis APIs.
2625
*
@@ -43,7 +42,9 @@ public function __construct(array $redisAPIs, $name, $timeout = 3)
4342
*/
4443
protected function add($redis, $key, $value, $expire)
4544
{
45+
/** @var Redis $redis */
4646
try {
47+
// Will set the key, if it doesn't exist, with a ttl of $expire seconds
4748
return $redis->set($key, $value, ["nx", "ex" => $expire]);
4849
} catch (RedisException $e) {
4950
$message = sprintf(
@@ -60,6 +61,7 @@ protected function add($redis, $key, $value, $expire)
6061
*/
6162
protected function evalScript($redis, $script, $numkeys, array $arguments)
6263
{
64+
/** @var Redis $redis */
6365
try {
6466
return $redis->eval($script, $arguments, $numkeys);
6567
} catch (RedisException $e) {
@@ -70,12 +72,13 @@ protected function evalScript($redis, $script, $numkeys, array $arguments)
7072
throw new LockReleaseException($message, 0, $e);
7173
}
7274
}
73-
75+
7476
/**
7577
* @internal
7678
*/
7779
protected function getRedisIdentifier($redis)
7880
{
81+
/** @var Redis $redis */
7982
return sprintf("redis://%s:%d?database=%s", $redis->getHost(), $redis->getPort(), $redis->getDBNum());
8083
}
8184
}

classes/mutex/RedisMutex.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ protected function release($key)
135135
* token, which results in releasing the wrong key.
136136
*/
137137

138+
/*
139+
* All Redis commands must be analyzed before execution to determine which keys the command will operate on. In
140+
* order for this to be true for EVAL, keys must be passed explicitly.
141+
*/
138142
$script = '
139143
if redis.call("get",KEYS[1]) == ARGV[1] then
140144
return redis.call("del",KEYS[1])

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"email": "[email protected]",
1212
"homepage": "http://markus.malkusch.de",
1313
"role": "Developer"
14+
},
15+
{
16+
"name": "Willem Stuursma-Ruwen",
17+
"email": "[email protected]",
18+
"role": "Developer"
1419
}
1520
],
1621
"autoload": {

0 commit comments

Comments
 (0)