mako\cache\Redis


Description


Redis adapter.


Class methods


Toggle source

public __construct($config)


Constructor.


Parameters

Type Description
array Configuration
Return value

NULL

public function __construct(array $config)
{
	parent::__construct($config['identifier']);
	
	$this->redis = new MRedis($config['configuration']);
}

Toggle source

public __destruct()


Destructor.

Return value

NULL

public function __destruct()
{
	if($this->redis !== null)
	{
		$this->redis = null;
	}
}

Toggle source

public write($key, $value, $ttl = 0)


Store variable in the cache.


Parameters

Type Description
string Cache key
mixed The variable to store
int (optional) Time to live
Return value

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;
}

Toggle source

public read($key)


Fetch variable from the cache.


Parameters

Type Description
string Cache key
Return value

mixed

public function read($key)
{
	$data = $this->redis->get("{$this->identifier}_{$key}");

	return ($data === null) ? false : unserialize($data);
}

Toggle source

public delete($key)


Delete a variable from the cache.


Parameters

Type Description
string Cache key
Return value

boolean

public function delete($key)
{
	return (bool) $this->redis->del("{$this->identifier}_{$key}");
}

Toggle source

public clear()


Clears the user cache.

Return value

boolean

public function clear()
{
	return (bool) $this->redis->flushdb();
}

final public remember($key, $closure, $ttl = 0)


Fetches variable from cache and stores it if it doesn't exist.


Parameters

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
Return value

mixed


final public __set($key, $value)


Magic setter.


Parameters

Type Description
string Cache key
mixed The variable to store
Return value

NULL


final public __get($key)


Magic getter.


Parameters

Type Description
string Cache key
Return value

mixed


final public __isset($key)


Magic isset.


Parameters

Type Description
string Cache key
Return value

boolean


final public __unset($key)


Magic unsetter.


Parameters

Type Description
string Cache key
Return value

NULL