PHP Class Neos\Cache\Backend\RedisBackend

Redis is a noSQL database with very good scaling characteristics in proportion to the amount of entries and data size.
See also: http://redis.io/
See also: https://github.com/nicolasff/phpredis Available backend options: - defaultLifetime: The default lifetime of a cache entry - hostname: The hostname (or socket filepath) of the redis server - port: The TCP port of the redis server (will be ignored if connecting to a socket) - database: The database index that will be used. By default, Redis has 16 databases with index number 0 - 15 Requirements: - Redis 2.6.0+ (tested with 2.6.14 and 2.8.5) - phpredis with Redis 2.6 support, e.g. 2.2.4 (tested with 92782639b0329ff91658a0602a3d816446a3663d from 2014-01-06) Implementation based on ext:rediscache by Christopher Hlubek - networkteam GmbH Each Redis key contains a prefix built from the cache identifier, so one single database can be used for different caches. Cache entry data is stored in a simple key. Tags are stored in Sets. Since Redis < 2.8.0 does not provide a mechanism for iterating over keys, a separate list with all entries is populated
Inheritance: extends AbstractBackend, implements Neos\Cache\Backend\TaggableBackendInterface, implements IterableBackendInterface, implements Neos\Cache\Backend\FreezableBackendInterface, implements Neos\Cache\Backend\PhpCapableBackendInterface, use trait RequireOnceFromValueTrait
Mostrar archivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$compressionLevel integer
$database integer
$entryCursor Cursor used for iterating over cache entries
$frozen boolean
$hostname string
$port integer
$redis Redis

Public Methods

Method Description
__construct ( EnvironmentConfiguration $environmentConfiguration, array $options ) Constructs this backend
collectGarbage ( ) : void This backend does not need an externally triggered garbage collection
current ( )
findIdentifiersByTag ( string $tag ) : array Finds and returns all cache entry identifiers which are tagged by the specified tag.
flush ( ) : void Removes all cache entries of this cache
flushByTag ( string $tag ) : integer Removes all cache entries of this cache which are tagged by the specified tag.
freeze ( ) : void Freezes this cache backend.
get ( string $entryIdentifier ) : mixed Loads data from the cache.
has ( string $entryIdentifier ) : boolean Checks if a cache entry with the specified identifier exists.
isFrozen ( ) : boolean Tells if this backend is frozen.
key ( )
next ( )
remove ( string $entryIdentifier ) : boolean Removes all cache entries matching the specified identifier.
rewind ( )
set ( string $entryIdentifier, string $data, array $tags = [], integer $lifetime = null ) : void Saves data in the cache.
setCompressionLevel ( integer $compressionLevel )
setDatabase ( integer $database ) Sets the database that will be used for this backend
setDefaultLifetime ( integer $lifetime ) : void Sets the default lifetime for this cache backend
setHostname ( string $hostname ) Sets the hostname or the socket of the Redis server
setPort ( string $port ) Sets the port of the Redis server.
setRedis ( Redis $redis = null )
valid ( )

Protected Methods

Method Description
verifyRedisVersionIsSupported ( ) : void

Private Methods

Method Description
buildKey ( $identifier ) : string
compress ( string $value ) : string
getRedisClient ( ) : Redis
uncompress ( string $value ) : string
useCompression ( ) : boolean

Method Details

__construct() public method

Constructs this backend
public __construct ( EnvironmentConfiguration $environmentConfiguration, array $options )
$environmentConfiguration Neos\Cache\EnvironmentConfiguration
$options array Configuration options - depends on the actual backend

collectGarbage() public method

This backend does not need an externally triggered garbage collection
public collectGarbage ( ) : void
return void

current() public method

public current ( )

findIdentifiersByTag() public method

Finds and returns all cache entry identifiers which are tagged by the specified tag.
public findIdentifiersByTag ( string $tag ) : array
$tag string The tag to search for
return array An array with identifiers of all matching entries. An empty array if no entries matched

flush() public method

The flush method will use the EVAL command to flush all entries and tags for this cache in an atomic way.
public flush ( ) : void
return void

flushByTag() public method

Removes all cache entries of this cache which are tagged by the specified tag.
public flushByTag ( string $tag ) : integer
$tag string The tag the entries must have
return integer The number of entries which have been affected by this flush

freeze() public method

All data in a frozen backend remains unchanged and methods which try to add or modify data result in an exception thrown. Possible expiry times of individual cache entries are ignored. A frozen backend can only be thawn by calling the flush() method.
public freeze ( ) : void
return void

get() public method

Loads data from the cache.
public get ( string $entryIdentifier ) : mixed
$entryIdentifier string An identifier which describes the cache entry to load
return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded

has() public method

Checks if a cache entry with the specified identifier exists.
public has ( string $entryIdentifier ) : boolean
$entryIdentifier string An identifier specifying the cache entry
return boolean TRUE if such an entry exists, FALSE if not

isFrozen() public method

Tells if this backend is frozen.
public isFrozen ( ) : boolean
return boolean

key() public method

public key ( )

next() public method

public next ( )

remove() public method

Usually this only affects one entry but if - for what reason ever - old entries for the identifier still exist, they are removed as well.
public remove ( string $entryIdentifier ) : boolean
$entryIdentifier string Specifies the cache entry to remove
return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found

rewind() public method

public rewind ( )

set() public method

Saves data in the cache.
public set ( string $entryIdentifier, string $data, array $tags = [], integer $lifetime = null ) : void
$entryIdentifier string An identifier for this specific cache entry
$data string The data to be stored
$tags array Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
$lifetime integer Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
return void

setCompressionLevel() public method

public setCompressionLevel ( integer $compressionLevel )
$compressionLevel integer

setDatabase() public method

Sets the database that will be used for this backend
public setDatabase ( integer $database )
$database integer Database that will be used

setDefaultLifetime() public method

Sets the default lifetime for this cache backend
public setDefaultLifetime ( integer $lifetime ) : void
$lifetime integer Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. 0 means unlimited lifetime.
return void

setHostname() public method

Sets the hostname or the socket of the Redis server
public setHostname ( string $hostname )
$hostname string Hostname of the Redis server

setPort() public method

Leave this empty if you want to connect to a socket
public setPort ( string $port )
$port string Port of the Redis server

setRedis() public method

public setRedis ( Redis $redis = null )
$redis Redis

valid() public method

public valid ( )

verifyRedisVersionIsSupported() protected method

protected verifyRedisVersionIsSupported ( ) : void
return void

Property Details

$compressionLevel protected_oe property

protected int $compressionLevel
return integer

$database protected_oe property

protected int $database
return integer

$entryCursor protected_oe property

Cursor used for iterating over cache entries
protected $entryCursor

$frozen protected_oe property

protected bool $frozen
return boolean

$hostname protected_oe property

protected string $hostname
return string

$port protected_oe property

protected int $port
return integer

$redis protected_oe property

protected Redis $redis
return Redis