summaryrefslogtreecommitdiffstats
path: root/lib/private/Memcache/Redis.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Memcache/Redis.php')
-rw-r--r--lib/private/Memcache/Redis.php40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php
index 4c8151b9d6c..bde25a3385a 100644
--- a/lib/private/Memcache/Redis.php
+++ b/lib/private/Memcache/Redis.php
@@ -31,23 +31,23 @@ namespace OC\Memcache;
use OCP\IMemcacheTTL;
-/** name => [script, sha1] */
-const LUA_SCRIPTS = [
- 'dec' => [
- 'if redis.call("exists", KEYS[1]) == 1 then return redis.call("decrby", KEYS[1], ARGV[1]) else return "NEX" end',
- '720b40cb66cef1579f2ef16ec69b3da8c85510e9',
- ],
- 'cas' => [
- 'if redis.call("get", KEYS[1]) == ARGV[1] then redis.call("set", KEYS[1], ARGV[2]) return 1 else return 0 end',
- '94eac401502554c02b811e3199baddde62d976d4',
- ],
- 'cad' => [
- 'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end',
- 'cf0e94b2e9ffc7e04395cf88f7583fc309985910',
- ],
-];
-
class Redis extends Cache implements IMemcacheTTL {
+ /** name => [script, sha1] */
+ public const LUA_SCRIPTS = [
+ 'dec' => [
+ 'if redis.call("exists", KEYS[1]) == 1 then return redis.call("decrby", KEYS[1], ARGV[1]) else return "NEX" end',
+ '720b40cb66cef1579f2ef16ec69b3da8c85510e9',
+ ],
+ 'cas' => [
+ 'if redis.call("get", KEYS[1]) == ARGV[1] then redis.call("set", KEYS[1], ARGV[2]) return 1 else return 0 end',
+ '94eac401502554c02b811e3199baddde62d976d4',
+ ],
+ 'cad' => [
+ 'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end',
+ 'cf0e94b2e9ffc7e04395cf88f7583fc309985910',
+ ],
+ ];
+
/**
* @var \Redis|\RedisCluster $cache
*/
@@ -185,10 +185,10 @@ class Redis extends Cache implements IMemcacheTTL {
return \OC::$server->getGetRedisFactory()->isAvailable();
}
- protected function evalLua($scriptName, $keys, $args) {
+ protected function evalLua(string $scriptName, array $keys, array $args) {
$keys = array_map(fn ($key) => $this->getPrefix() . $key, $keys);
$args = array_merge($keys, $args);
- $script = LUA_SCRIPTS[$scriptName];
+ $script = self::LUA_SCRIPTS[$scriptName];
$result = $this->getCache()->evalSha($script[1], $args, count($keys));
if (false === $result) {
@@ -198,11 +198,11 @@ class Redis extends Cache implements IMemcacheTTL {
return $result;
}
- protected static function encodeValue($value) {
+ protected static function encodeValue(mixed $value): string {
return is_int($value) ? (string) $value : json_encode($value);
}
- protected static function decodeValue($value) {
+ protected static function decodeValue(string $value): mixed {
return is_numeric($value) ? (int) $value : json_decode($value, true);
}
}