[CORE][Cache] Add Cache::incr which increments a value at , atomically, in the case of Redis

This commit is contained in:
Hugo Sales 2022-01-04 18:53:35 +00:00
parent a5b5362be2
commit b7e4f79ccc
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -169,6 +169,15 @@ abstract class Cache
}
}
public static function incr(string $key, string $pool = 'default')
{
if (isset(self::$redis[$pool])) {
return self::$redis[$pool]->incr($key);
} else {
return self::$pools[$pool]->set($key, 1 + self::$pools[$pool]->get($key, fn ($i) => 0), \INF);
}
}
public static function set(string $key, mixed $value, string $pool = 'default')
{
if (isset(self::$redis[$pool])) {