PHP Класс lithium\storage\cache\adapter\Redis

This adapter uses the phpredis PHP extension, which can be found here: https://github.com/nicolasff/phpredis The Redis cache adapter is meant to be used through the Cache interface, which abstracts away key generation, adapter instantiation and filter implementation. This adapter does not aim to provide a full implementation of the Redis API, but rather only a subset of its features that are useful in the context of a semi-persistent cache. A simple configuration of this adapter can be accomplished in config/bootstrap/cache.php as follows: {{{ Cache::config(array( 'cache-config-name' => array( 'adapter' => 'Redis', 'host' => '127.0.0.1:6379' ) )); }}} The 'host' key accepts a string argument in the format of ip:port where the Redis server can be found. This Redis adapter provides basic support for write, read, delete and clear cache functionality, as well as allowing the first four methods to be filtered as per the Lithium filtering system.
См. также: lithium\storage\Cache::key()
См. также: lithium\storage\Cache::adapter()
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$connection Redis object instance used by this adapter.

Открытые методы

Метод Описание
__call ( string $method, array $params = [] ) : mixed Dispatches a not-found method to the connection object. That way, one can easily use a custom method on the adapter. If you want to know, what methods are available, have a look at the documentation of phpredis.
__construct ( array $config = [] ) : void Constructor.
clear ( ) : boolean Clears entire database by flushing it. All cache keys using the configuration but *without* honoring the scope are removed.
decrement ( string $key, integer $offset = 1 ) : integer | boolean Performs an atomic decrement operation on specified numeric cache item.
delete ( array $keys ) : boolean Will attempt to remove specified keys from the user space cache.
enabled ( ) : boolean Determines if the Redis extension has been installed and that there is a Redis server available.
increment ( string $key, integer $offset = 1 ) : integer | boolean Performs an atomic increment operation on specified numeric cache item.
read ( array $keys ) : array Read values from the cache. Will attempt to return an array of data containing key/value pairs of the requested data.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
write ( array $keys, string | integer $expiry = null ) : boolean Write values to the cache. All items to be cached will receive an expiration time of $expiry.

Защищенные методы

Метод Описание
_formatHost ( mixed $host ) : array Formats standard 'host:port' or '/path/to/socket' strings
_init ( ) : void Initialize the Redis connection object, connect to the Redis server and sets prefix using the scope if provided.

Описание методов

__call() публичный Метод

Cache::adapter('redis')->methodName($argument); One use-case might be to query possible keys, e.g. Cache::adapter('redis')->keys('*');
public __call ( string $method, array $params = [] ) : mixed
$method string Name of the method to call.
$params array Parameter list to use when calling $method.
Результат mixed Returns the result of the method call.

__construct() публичный Метод

Constructor.
См. также: lithium\storage\Cache::config()
См. также: lithium\storage\cache\adapter\Redis::write()
public __construct ( array $config = [] ) : void
$config array Configuration for this cache adapter. These settings are queryable through `Cache::config('name')`. The available options are as follows: - `'scope'` _string_: Scope which will prefix keys; per default not set. - `'expiry'` _mixed_: The default expiration time for cache values, if no value is otherwise set. Can be either a `strtotime()` compatible tring or TTL in seconds. To indicate items should not expire use `Cache::PERSIST`. Defaults to `+1 hour`. - `'host'` _string_: A string in the form of `'host:port'` indicating the Redis server to connect to. Defaults to `'127.0.0.1:6379'`. - `'persistent'` _boolean_: Indicates whether the adapter should use a persistent connection when attempting to connect to the Redis server. If `true`, it will attempt to reuse an existing connection when connecting, and the connection will not close when the request is terminated. Defaults to `false`.
Результат void

_formatHost() защищенный Метод

Formats standard 'host:port' or '/path/to/socket' strings
protected _formatHost ( mixed $host ) : array
$host mixed A host string in `'host:port'` or `'/path/to/socket'` format
Результат array Returns an array of `Redis` connection definitions.

_init() защищенный Метод

Initialize the Redis connection object, connect to the Redis server and sets prefix using the scope if provided.
protected _init ( ) : void
Результат void

clear() публичный Метод

The behavior and result when removing a single key during this process fails is unknown.
public clear ( ) : boolean
Результат boolean `true` on successful clearing, `false` otherwise.

decrement() публичный Метод

Note that if the value of the specified key is *not* an integer, the decrement operation will have no effect whatsoever. Redis chooses to not typecast values to integers when performing an atomic decrement operation.
public decrement ( string $key, integer $offset = 1 ) : integer | boolean
$key string Key of numeric cache item to decrement.
$offset integer Offset to decrement - defaults to `1`.
Результат integer | boolean The item's new value on successful decrement, else `false`.

delete() публичный Метод

Will attempt to remove specified keys from the user space cache.
public delete ( array $keys ) : boolean
$keys array Keys to uniquely identify the cached items.
Результат boolean `true` on successful delete, `false` otherwise.

enabled() публичный статический Метод

Determines if the Redis extension has been installed and that there is a Redis server available.
public static enabled ( ) : boolean
Результат boolean Returns `true` if the Redis extension is enabled, `false` otherwise.

increment() публичный Метод

Note that if the value of the specified key is *not* an integer, the increment operation will have no effect whatsoever. Redis chooses to not typecast values to integers when performing an atomic increment operation.
public increment ( string $key, integer $offset = 1 ) : integer | boolean
$key string Key of numeric cache item to increment.
$offset integer Offset to increment - defaults to `1`.
Результат integer | boolean The item's new value on successful increment, else `false`.

read() публичный Метод

Read values from the cache. Will attempt to return an array of data containing key/value pairs of the requested data.
public read ( array $keys ) : array
$keys array Keys to uniquely identify the cached items.
Результат array Cached values keyed by cache keys on successful read, keys which could not be read will not be included in the results array.

respondsTo() публичный Метод

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
Результат boolean Returns `true` if the method can be called, `false` otherwise.

write() публичный Метод

Write values to the cache. All items to be cached will receive an expiration time of $expiry.
public write ( array $keys, string | integer $expiry = null ) : boolean
$keys array Key/value pairs with keys to uniquely identify the to-be-cached item.
$expiry string | integer A `strtotime()` compatible cache time or TTL in seconds. To persist an item use `\lithium\storage\Cache::PERSIST`.
Результат boolean `true` on successful write, `false` otherwise.

Описание свойств

$connection публичное свойство

Redis object instance used by this adapter.
public $connection