get('config'); $redisConfig = $config->get('redis'); $this->redis = new \Redis(); (array_key_exists('port', $redisConfig)) ? $this->redis->pconnect($redisConfig['host'], $redisConfig['port']) : $this->redis->pconnect($redisConfig['host']); // If there is a password, authorize if (array_key_exists('password', $redisConfig)) { $this->redis->auth($redisConfig['password']); } // If there is a database selected, connect to the specified database if (array_key_exists('database', $redisConfig)) { $this->redis->select($redisConfig['database']); } $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); } /** * Destructor to disconnect from redis */ public function __destruct() { $this->redis->close(); } /** * Retreive a value from the cache backend * * @param string $key * @return mixed */ public function get($key) { return $this->redis->get($key); } /** * Set a cached value * * @param string $key * @param mixed $value * @return CacheDriverInterface */ public function set($key, $value) { $this->redis->set($key, $value); return $this; } /** * Invalidate a cached value * * @param string $key * @return CacheDriverInterface */ public function invalidate($key) { $this->redis->del($key); return $this; } /** * Clear the contents of the cache * * @return void */ public function invalidateAll() { $this->redis->flushDB(); } } // End of RedisDriver.php