Skip to content

Commit 845d29e

Browse files
Fixes #14. Locking does not work correctly when a serialization mode is enabled with the Redis extension.
1 parent 0f1771d commit 845d29e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

classes/mutex/PHPRedisMutex.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ protected function add($redis, $key, $value, $expire)
6262
protected function evalScript($redis, $script, $numkeys, array $arguments)
6363
{
6464
/** @var Redis $redis */
65+
66+
/*
67+
* If a serializion mode such as "php" or "igbinary" is enabled, the arguments must be serialized but the keys
68+
* must not.
69+
*
70+
* @issue 14
71+
*/
72+
for ($i = $numkeys, $iMax = \count($arguments); $i < $iMax; $i++) {
73+
$arguments[$i] = $redis->_serialize($arguments[$i]);
74+
}
75+
6576
try {
6677
return $redis->eval($script, $arguments, $numkeys);
6778
} catch (RedisException $e) {

tests/mutex/PHPRedisMutexTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,25 @@ public function testEvalScriptFails()
7777
$this->redis->close();
7878
});
7979
}
80+
81+
/**
82+
* @param $serialization
83+
* @dataProvider dpSerializationModes
84+
*/
85+
public function testSyncronizedWorks($serialization)
86+
{
87+
$this->redis->setOption(Redis::OPT_SERIALIZER, $serialization);
88+
89+
$this->mutex->synchronized(function () {
90+
$this->assertTrue(true);
91+
});
92+
}
93+
94+
public function dpSerializationModes() {
95+
return [
96+
[Redis::SERIALIZER_NONE],
97+
[Redis::SERIALIZER_PHP],
98+
[Redis::SERIALIZER_IGBINARY],
99+
];
100+
}
80101
}

0 commit comments

Comments
 (0)