From b7e4f79cccffd84d786a6cb67b08d2207caa4609 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 4 Jan 2022 18:53:35 +0000 Subject: [PATCH] [CORE][Cache] Add Cache::incr which increments a value at , atomically, in the case of Redis --- src/Core/Cache.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Core/Cache.php b/src/Core/Cache.php index bcbb48fc49..c9bad6a6c8 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -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])) {