Skip to content

Commit c7516e0

Browse files
committed
Refactored PHPRedisMutex to extract lzf compression detection.
1 parent ffabb4b commit c7516e0

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

classes/mutex/PHPRedisMutex.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ protected function add($redisAPI, string $key, string $value, int $expire): bool
6969
*/
7070
protected function evalScript($redis, string $script, int $numkeys, array $arguments)
7171
{
72-
// Determine if we need to compress eval arguments.
73-
$lzfCompression = false;
74-
if (defined("Redis::COMPRESSION_LZF") &&
75-
Redis::COMPRESSION_LZF === $redis->getOption(Redis::OPT_COMPRESSION) &&
76-
function_exists('lzf_compress')
77-
) {
78-
$lzfCompression = true;
79-
}
80-
8172
for ($i = $numkeys, $iMax = count($arguments); $i < $iMax; $i++) {
8273
/* If a serializion mode such as "php" or "igbinary" is enabled, the arguments must be
8374
* serialized by us, because phpredis does not do this for the eval command.
@@ -87,7 +78,7 @@ function_exists('lzf_compress')
8778
/* If LZF compression is enabled for the redis connection and the runtime has the LZF
8879
* extension installed, compress the arguments as the final step.
8980
*/
90-
if ($lzfCompression) {
81+
if ($this->hasLzfCompression($redis)) {
9182
$arguments[$i] = lzf_compress($arguments[$i]);
9283
}
9384
}
@@ -98,4 +89,22 @@ function_exists('lzf_compress')
9889
throw new LockReleaseException("Failed to release lock", 0, $e);
9990
}
10091
}
92+
93+
/**
94+
* Determines if lzf compression is enabled for the given connection.
95+
*
96+
* @param \Redis|\RedisCluster $redis Redis connection.
97+
* @return bool TRUE if lzf comression is enabled, false otherwise.
98+
*/
99+
private function hasLzfCompression($redis): bool
100+
{
101+
if (\defined('Redis::COMPRESSION_LZF') &&
102+
Redis::COMPRESSION_LZF === $redis->getOption(Redis::OPT_COMPRESSION) &&
103+
\function_exists('lzf_compress')
104+
) {
105+
return true;
106+
}
107+
108+
return false;
109+
}
101110
}

0 commit comments

Comments
 (0)