/** * Gets the value of a key. * * @param string $key * * @return mixed The value of the key. * * @throws KeyNotFoundException * @throws \Exception */ public function get($key) { $getResult = $this->getValue($key); $unserialized = @unserialize($getResult); if (Util::hasInternalExpireTime($unserialized)) { $getResult = $unserialized['v']; } return $getResult; }
/** * Gets value, watches expiring. * * @param string $key * * @return mixed * * @throws KeyNotFoundException */ protected function getValue($key) { if (!array_key_exists($key, $this->store)) { throw new KeyNotFoundException(); } $getResult = $this->store[$key]; $unserialized = @unserialize($getResult); if (Util::hasInternalExpireTime($unserialized)) { $this->handleTtl($key, $unserialized['ts'], $unserialized['s']); $getResult = $unserialized['v']; } return $getResult; }
/** * Gets value, watches expiring. * * @param string $key * * @return mixed * * @throws KeyNotFoundException * @throws \Exception */ protected function getValue($key) { if (!$this->shmProxy->has($this->client, $key)) { throw new KeyNotFoundException(); } $getResult = $this->shmProxy->get($this->client, $key); $unserialized = @unserialize($getResult); if (Util::hasInternalExpireTime($unserialized)) { $this->handleTtl($key, $unserialized['ts'], $unserialized['s']); $getResult = $unserialized['v']; } return $getResult; }
/** * Removes the existing timeout on key, turning the key from volatile (a key with an expire set) * to persistent (a key that will never expire as no timeout is associated). * * @param string $key * * @return bool True if the persist was success, false if the persis was unsuccessful. * * @throws \Exception */ public function persist($key) { $getResult = $this->getValue($key); $unserialized = @unserialize($getResult); if (!Util::hasInternalExpireTime($unserialized)) { return false; } return $this->getClient()->replace($key, $unserialized['v'], 0); }
/** * Removes the existing timeout on key, turning the key from volatile (a key with an expire set) * to persistent (a key that will never expire as no timeout is associated). * * @param string $key * * @return bool True if the persist was success, false if the persis was unsuccessful. * * @throws \Exception */ public function persist($key) { try { $getResult = $this->getValue($key); } catch (KeyNotFoundException $e) { return false; } $unserialized = @unserialize($getResult); if (!Util::hasInternalExpireTime($unserialized)) { return false; } try { $this->handleTtl($key, $unserialized['ts'], $unserialized['s']); } catch (KeyNotFoundException $e) { return false; } return $this->set($key, $unserialized['v']); }
/** * Removes the existing timeout on key, turning the key from volatile (a key with an expire set) * to persistent (a key that will never expire as no timeout is associated). * * @param string $key * * @return bool True if the persist was success, false if the persis was unsuccessful. * * @throws \Exception */ public function persist($key) { $getResult = $this->getValue($key); $unserialized = @unserialize($getResult); if (!Util::hasInternalExpireTime($unserialized)) { throw new \Exception("{$key} has no associated timeout"); } return $this->getClient()->replace($key, $unserialized['v'], false, 0); }