Skip to content

Commit f78bc05

Browse files
Redis: change to int keys because of type confusion between set and script
1 parent 3dc1509 commit f78bc05

File tree

4 files changed

+34
-36
lines changed

4 files changed

+34
-36
lines changed

classes/mutex/PHPRedisMutex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(array $redisAPIs, string $name, int $timeout = 3)
3737
parent::__construct($redisAPIs, $name, $timeout);
3838
}
3939

40-
protected function add($redis, string $key, string $value, int $expire): bool
40+
protected function add($redis, string $key, int $value, int $expire): bool
4141
{
4242
/** @var Redis $redis */
4343
try {

classes/mutex/PredisMutex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(array $clients, string $name, int $timeout = 3)
3333
parent::__construct($clients, $name, $timeout);
3434
}
3535

36-
protected function add($client, string $key, string $value, int $expire): bool
36+
protected function add($client, string $key, int $value, int $expire): bool
3737
{
3838
/** @var ClientInterface $client */
3939
try {
@@ -61,7 +61,7 @@ protected function evalScript($client, string $script, int $numkeys, array $argu
6161
throw new LockReleaseException($message, 0, $e);
6262
}
6363
}
64-
64+
6565
/**
6666
* @internal
6767
*/

classes/mutex/RedisMutex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function isMajority(int $count): bool
186186
* @throws LockAcquireException An unexpected error happened.
187187
* @internal
188188
*/
189-
abstract protected function add($redisAPI, string $key, string $value, int $expire): bool;
189+
abstract protected function add($redisAPI, string $key, int $value, int $expire): bool;
190190

191191
/**
192192
* @param mixed $redisAPI The connected Redis API.

tests/mutex/MutexConcurrencyTest.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -268,39 +268,37 @@ public function provideMutexFactories()
268268
}];
269269
}
270270

271-
if (getenv("REDIS_URIS") && PHP_VERSION >= "7") {
272-
$uris = explode(",", getenv("REDIS_URIS"));
273-
274-
$cases["PredisMutex"] = [function ($timeout = 3) use ($uris): Mutex {
275-
$clients = array_map(
276-
function ($uri) {
277-
return new Client($uri);
278-
},
279-
$uris
280-
);
281-
return new PredisMutex($clients, "test", $timeout);
282-
}];
271+
$uris = getenv("REDIS_URIS") !== false ? explode(",", getenv("REDIS_URIS")) : ["redis://localhost:6379"];
283272

284-
$cases["PHPRedisMutex"] = [function ($timeout = 3) use ($uris): Mutex {
285-
/** @var Redis[] $apis */
286-
$apis = array_map(
287-
function (string $uri): Redis {
288-
$redis = new Redis();
289-
290-
$uri = parse_url($uri);
291-
if (!empty($uri["port"])) {
292-
$redis->connect($uri["host"], $uri["port"]);
293-
} else {
294-
$redis->connect($uri["host"]);
295-
}
296-
297-
return $redis;
298-
},
299-
$uris
300-
);
301-
return new PHPRedisMutex($apis, "test", $timeout);
302-
}];
303-
}
273+
$cases["PredisMutex"] = [function ($timeout = 3) use ($uris): Mutex {
274+
$clients = array_map(
275+
function ($uri) {
276+
return new Client($uri);
277+
},
278+
$uris
279+
);
280+
return new PredisMutex($clients, "test", $timeout);
281+
}];
282+
283+
$cases["PHPRedisMutex"] = [function ($timeout = 3) use ($uris): Mutex {
284+
/** @var Redis[] $apis */
285+
$apis = array_map(
286+
function (string $uri): Redis {
287+
$redis = new Redis();
288+
289+
$uri = parse_url($uri);
290+
if (!empty($uri["port"])) {
291+
$redis->connect($uri["host"], $uri["port"]);
292+
} else {
293+
$redis->connect($uri["host"]);
294+
}
295+
296+
return $redis;
297+
},
298+
$uris
299+
);
300+
return new PHPRedisMutex($apis, "test", $timeout);
301+
}];
304302

305303
if (getenv("MYSQL_DSN")) {
306304
$cases["MySQLMutex"] = [function ($timeout = 3): Mutex {

0 commit comments

Comments
 (0)