[CORE][Cache] Add Cache::incr which increments a value at , atomically, in the case of Redis
This commit is contained in:
parent
a5b5362be2
commit
b7e4f79ccc
|
@ -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])) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user