redisClient = $redisClient; parent::__construct($keyPrefix); } /** * Attempt to retrieve a value from the cache * * @param string $name * @param int $type * @param callable $callback */ public function get($name, $type, callable $callback) { list($wasHit, $value) = $this->redisClient->eval($this->fetchLuaScript, 1, $this->generateKey($name, $type)); if ($wasHit) { $callback(true, $value); return; } $callback(false, null); } /** * Stores a value in the cache. Overwrites the previous value if there was one. * * @param string $name * @param int $type * @param string $addr * @param int $ttl */ public function store($name, $type, $addr, $ttl = null) { $key = $this->generateKey($name, $type); if ($ttl > 0) { $this->redisClient->set($key, $addr, 'EX', (int)$ttl); } else { $this->redisClient->set($key, $addr); } } /** * Deletes an entry from the cache. * * @param string $name * @param int $type */ public function delete($name, $type) { $this->redisClient->del([$this->generateKey($name, $type)]); } }