/** * {@inheritdoc} */ public function update($key, callable $modifier, $ttl = 0) { $this->redis->watch($key); $data = $this->redis->get($key); if ($data === false) { $this->redis->unwatch(); return false; } else { $modifier($data); if ($this->setInTransaction($key, $data, (int) $ttl)) { return $data; } } throw new AtomicViolationException("Atomic violation occurred when updating key \"{$key}\"."); }
/** * Turns a key array into a key string. This includes running the indexing functions used to manage the Redis * hierarchical storage. * * When requested the actual path, rather than a normalized value, is returned. * * @param array $key * @param bool $path * @return string */ protected function makeKeyString($key, $path = false) { $key = \Stash\Utilities::normalizeKeys($key); $keyString = 'cache:::'; $pathKey = ':pathdb::'; foreach ($key as $name) { //a. cache:::name //b. cache:::name0:::sub $keyString .= $name; //a. :pathdb::cache:::name //b. :pathdb::cache:::name0:::sub $pathKey = ':pathdb::' . $keyString; $pathKey = md5($pathKey); if (isset($this->keyCache[$pathKey])) { $index = $this->keyCache[$pathKey]; } else { $index = $this->redis->get($pathKey); $this->keyCache[$pathKey] = $index; } //a. cache:::name0::: //b. cache:::name0:::sub1::: $keyString .= '_' . $index . ':::'; } return $path ? $pathKey : md5($keyString); }