Created
June 22, 2013 10:01
-
-
Save mCzolko/5840248 to your computer and use it in GitHub Desktop.
Simple redis client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Michael Czolko <[email protected]> | |
* Date: 6/21/13 | |
* Time: 9:16 PM | |
*/ | |
namespace flow\simple\cache; | |
use flow\Config; | |
use \Predis\Client as RedisClient; | |
class Redis implements ICache { | |
/** @var \Predis\Client */ | |
private $redisClient; | |
/** | |
* @param array $configuration | |
*/ | |
public function __construct(Config $configuration) { | |
$this->redisClient = new RedisClient((array) $configuration->redis); | |
} | |
/** | |
* @param $key | |
* @param $value | |
* @return bool True means successfull save to Redis. | |
*/ | |
public function set($key, $value) { | |
try { | |
$this->redisClient->set($key, $value); | |
} catch (\Exception $e) { | |
return false; | |
} | |
return true; | |
} | |
/** | |
* @param $key | |
* @param null $fallback | |
* @return string|null | |
*/ | |
public function get($key, $fallback = null) { | |
try { | |
return $this->redisClient->get($key); | |
} catch (\Exception $e) { | |
return $fallback; | |
} | |
} | |
/** | |
* @param $key | |
* @return bool|void | |
*/ | |
public function remove($key) { | |
$this->set($key, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment