+ $cachekey = $this->getCacheKey($key);
+
+ $newCached = serialize($newValue);
+
+ $this->redis->watch($cachekey);
+ // If the old value isn't what we expected, somebody else changed the key meanwhile
+ if ($this->get($key) === $oldValue) {
+ if ($ttl > 0) {
+ $result = $this->redis->multi()
+ ->setex($cachekey, $ttl, $newCached)
+ ->exec();
+ } else {
+ $result = $this->redis->multi()
+ ->set($cachekey, $newValue)
+ ->exec();
+ }
+ return $result !== false;
+ }
+ $this->redis->unwatch();
+ return false;
+ }
+ /**
+ * (@inheritdoc)
+ */
+ public function compareDelete($key, $value)
+ {
+ $cachekey = $this->getCacheKey($key);
+
+ $this->redis->watch($cachekey);
+ // If the old value isn't what we expected, somebody else changed the key meanwhile
+ if ($this->get($key) === $value) {
+ $result = $this->redis->multi()
+ ->del($cachekey)
+ ->exec();
+ return $result !== false;
+ }
+ $this->redis->unwatch();
+ return false;