Redis adapter.
Constructor.
| Type | Description |
|---|---|
| array | Configuration |
NULL
public function __construct(array $config)
{
parent::__construct($config['identifier']);
$this->redis = new MRedis($config['configuration']);
}
Destructor.
NULL
public function __destruct()
{
if($this->redis !== null)
{
$this->redis = null;
}
}
Store variable in the cache.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
| int | (optional) Time to live |
boolean
public function write($key, $value, $ttl = 0)
{
$this->redis->set("{$this->identifier}_{$key}", serialize($value));
if($ttl !== 0)
{
$this->redis->expire("{$this->identifier}_{$key}", $ttl);
}
return true;
}
Fetch variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
mixed
public function read($key)
{
$data = $this->redis->get("{$this->identifier}_{$key}");
return ($data === null) ? false : unserialize($data);
}
Delete a variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
boolean
public function delete($key)
{
return (bool) $this->redis->del("{$this->identifier}_{$key}");
}
Clears the user cache.
boolean
public function clear()
{
return (bool) $this->redis->flushdb();
}
Fetches variable from cache and stores it if it doesn't exist.
| Type | Description |
|---|---|
| string | Cache key |
| closure | Closure (anonymous function) that returns value to store if it doesn't already exist |
| int | (optional) Time to live |
mixed
Magic setter.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
NULL
Magic getter.
| Type | Description |
|---|---|
| string | Cache key |
mixed
Magic isset.
| Type | Description |
|---|---|
| string | Cache key |
boolean
Magic unsetter.
| Type | Description |
|---|---|
| string | Cache key |
NULL