RedisCache

Type
Class
Namespace
Craft
Inherits
Craft\RedisCache » CRedisCache » CCache » CApplicationComponent » CComponent
Implements
ArrayAccess, IApplicationComponent, ICache
Since
2.0

RedisCache implements a cache application component based on redis.

RedisCache needs to be configured with {@link hostname}, {@link port} and {@link database} of the server to connect to. By default RedisCache assumes there is a redis server running on localhost at port 6379 and uses the database number 0.

RedisCache also supports the AUTH command of redis. When the server needs authentication, you can set the {@link password} property to authenticate with the server after connect.

The minimum required redis version is 2.0.0.

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$behaviorsarray – The behaviors that should be attached to this component.
$databaseinteger – The redis database to use.
$hashKeyboolean – Whether to md5-hash the cache key for normalization purposes.
$hostnamestring – Hostname to use for connecting to the redis server.
$keyPrefixstring – A string prefixed to every cache key so that it is unique.
$optionsinteger – The options to pass to the flags parameter of stream_socket_client when connecting to the redis server.
$passwordstring – The password to use to authenticate with the redis server.
$portinteger – The port to use for connecting to the redis server.
$serializerarray, boolean – The functions used to serialize and unserialize cached data.
$timeoutfloat – Timeout to use for connection to redis.

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
add()Stores a value identified by a key into cache if the cache does not contain this key.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
delete()Deletes a value with the specified key from cache
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
executeCommand()Executes a redis command.
flush()Deletes all values from cache.
get()Retrieves a value from cache with a specified key.
getEventHandlers()Returns the list of attached event handlers for an event.
getIsInitialized()Checks if this application component has been initialized.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
init()Initializes the application component.
mget()Retrieves multiple values from cache with the specified keys.
offsetExists()Returns whether there is a cache entry with a specified key.
offsetGet()Retrieves the value from cache with a specified key.
offsetSet()Stores the value identified by a key into cache.
offsetUnset()Deletes the value with the specified key from cache This method is required by the interface ArrayAccess.
raiseEvent()Raises an event.
set()Stores a value identified by a key into cache.

Protected Methods

MethodDescription
addValue()Stores a value identified by a key into cache if the cache does not contain this key.
connect()Establishes a connection to the redis server. It does nothing if the connection has already been established.
deleteValue()Deletes a value with the specified key from cache This method should be implemented by child classes to delete the data from actual cache storage.
flushValues()Deletes all values from cache.
generateUniqueKey()
getValue()Retrieves a value from cache with a specified key.
getValues()Retrieves multiple values from cache with the specified keys.
setValue()Stores a value identified by a key in cache.

connect()

Establishes a connection to the redis server. It does nothing if the connection has already been established. Craft overrides this from Yii because the parent is explicitly checking for null in the password.

View source

Returns

null

Throws

Signature

protected null connect ( )