aboutsummaryrefslogtreecommitdiffstats
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.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php
index bde25a3385a..7bd29d1cecf 100644
--- a/lib/private/Memcache/Redis.php
+++ b/lib/private/Memcache/Redis.php
@@ -181,6 +181,23 @@ class Redis extends Cache implements IMemcacheTTL {
$this->getCache()->expire($this->getPrefix() . $key, $ttl);
}
+ public function getTTL(string $key): int|false {
+ $ttl = $this->getCache()->ttl($this->getPrefix() . $key);
+ return $ttl > 0 ? (int)$ttl : false;
+ }
+
+ public function compareSetTTL(string $key, mixed $value, int $ttl): bool {
+ $fullKey = $this->getPrefix() . $key;
+ $redis = $this->getCache();
+ if ($this->get($key) === $value) {
+ $result = $redis->multi()
+ ->expire($fullKey, $ttl)
+ ->exec();
+ return $result !== false;
+ }
+ return false;
+ }
+
public static function isAvailable(): bool {
return \OC::$server->getGetRedisFactory()->isAvailable();
}