redisClient = $redisClient; $this->prefix = $prefixKey; } /** * Stores a value in the cache. Overwrites the previous value if there was one. * * @param string $name * @param string $value * @param int $ttl */ public function store($name, $value, $ttl = null) { $name = $this->prefix . $name; $ttl = intval($ttl); if ($ttl > 0) { $this->redisClient->set($name, $value, 'EX', $ttl); } else { $this->redisClient->set($name, $value); } } /** * Attempt to retrieve a value from the cache * * Returns an array [$cacheHit, $value] * [true, $valueFromCache] - if it existed in the cache * [false, null] - if it didn't already exist in the cache * * @param $name * @return array */ public function get($name) { $name = $this->prefix . $name; list($wasHit, $value) = $this->redisClient->eval($this->fetchLuaScript, 1, $name); if ($wasHit) { return [true, $value]; } return [false, null]; } /** * @param $name */ public function delete($name) { $name = $this->prefix . $name; $this->redisClient->del([$name]); } }