Skip to content

Instantly share code, notes, and snippets.

@mCzolko
Created June 22, 2013 10:01
Show Gist options
  • Save mCzolko/5840248 to your computer and use it in GitHub Desktop.
Save mCzolko/5840248 to your computer and use it in GitHub Desktop.
Simple redis client
<?php
/**
* @author Michael Czolko <michael@czolko.cz>
* 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