‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Cache\Backend\RedisBackend Class Reference
Inheritance diagram for TYPO3\CMS\Core\Cache\Backend\RedisBackend:
TYPO3\CMS\Core\Cache\Backend\AbstractBackend TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface TYPO3\CMS\Core\Cache\Backend\BackendInterface TYPO3\CMS\Core\Cache\Backend\BackendInterface

Public Member Functions

 __construct ($context, array $options=[])
 
 initializeObject ()
 
 setPersistentConnection ($persistentConnection)
 
 setHostname ($hostname)
 
 setPort ($port)
 
 setDatabase ($database)
 
 setPassword ($password)
 
 setCompression ($compression)
 
 setCompressionLevel ($compressionLevel)
 
 setConnectionTimeout ($connectionTimeout)
 
 set ($entryIdentifier, $data, array $tags=[], $lifetime=null)
 
mixed get ($entryIdentifier)
 
bool has ($entryIdentifier)
 
bool remove ($entryIdentifier)
 
array findIdentifiersByTag ($tag)
 
 flush ()
 
 flushByTag ($tag)
 
 collectGarbage ()
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
 setCache (FrontendInterface $cache)
 
 setDefaultLifetime ($defaultLifetime)
 
 flushByTags (array $tags)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
 flushByTags (array $tags)
 

Public Attributes

const FAKED_UNLIMITED_LIFETIME = 31536000
 
const IDENTIFIER_DATA_PREFIX = 'identData:'
 
const IDENTIFIER_TAGS_PREFIX = 'identTags:'
 
const TAG_IDENTIFIERS_PREFIX = 'tagIdents:'
 
- ‪Public Attributes inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'
 
const UNLIMITED_LIFETIME = 0
 

Protected Member Functions

 removeIdentifierEntriesAndRelations (array $identifiers, array $tags)
 
bool canBeUsedInStringContext ($variable)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
DateTime calculateExpiryTime ($lifetime=null)
 

Protected Attributes

Redis $redis
 
bool $connected = false
 
bool $persistentConnection = false
 
string $hostname = '127.0.0.1'
 
int $port = 6379
 
int $database = 0
 
string $password = ''
 
bool $compression = false
 
int $compressionLevel = -1
 
int $connectionTimeout = 0
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
FrontendInterface $cache
 
string $cacheIdentifier
 
string $context
 
int $defaultLifetime = 3600
 

Detailed Description

A caching backend which stores cache entries by using Redis with phpredis PHP module. Redis is a noSQL database with very good scaling characteristics in proportion to the amount of entries and data size.

See also
https://redis.io/
https://github.com/phpredis/phpredis

Definition at line 30 of file RedisBackend.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::__construct (   $context,
array  $options = [] 
)

Construct this backend

Parameters
string$context‪Unused, for backward compatibility only
array$optionsConfiguration options
Exceptions
Exception‪if php redis module is not loaded

Reimplemented from TYPO3\CMS\Core\Cache\Backend\AbstractBackend.

Definition at line 131 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$context.

Member Function Documentation

◆ canBeUsedInStringContext()

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::canBeUsedInStringContext (   $variable)
protected

◆ collectGarbage()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::collectGarbage ( )

With the current internal structure, only the identifier to data entries have a redis internal lifetime. If an entry expires, attached identifier to tags and tag to identifiers entries will be left over. This methods finds those entries and cleans them up.

Scales O(n*m) with number of cache entries (n) and number of tags (m)

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 477 of file RedisBackend.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ findIdentifiersByTag()

array TYPO3\CMS\Core\Cache\Backend\RedisBackend::findIdentifiersByTag (   $tag)

Finds and returns all cache entry identifiers which are tagged by the specified tag.

Scales O(1) with number of cache entries Scales O(n) with number of tag entries

Parameters
string$tag‪The tag to search for
Returns
‪array An array of entries with all matching entries. An empty array if no entries matched
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface.

Definition at line 423 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext().

◆ flush()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::flush ( )

Removes all cache entries of this cache.

Scales O(1) with number of cache entries

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 440 of file RedisBackend.php.

◆ flushByTag()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::flushByTag (   $tag)

Removes all cache entries of this cache which are tagged with the specified tag.

Scales O(1) with number of cache entries Scales O(n^2) with number of tag entries

Parameters
string$tag‪Tag the entries must have
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface.

Definition at line 456 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext(), and TYPO3\CMS\Core\Cache\Backend\RedisBackend\removeIdentifierEntriesAndRelations().

◆ get()

mixed TYPO3\CMS\Core\Cache\Backend\RedisBackend::get (   $entryIdentifier)

Loads data from the cache.

Scales O(1) with number of cache entries

Parameters
string$entryIdentifier‪An identifier which describes the cache entry to load
Returns
‪mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 349 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext().

◆ has()

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::has (   $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

Scales O(1) with number of cache entries

Parameters
string$entryIdentifier‪Identifier specifying the cache entry
Returns
‪bool TRUE if such an entry exists, FALSE if not
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 373 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext().

◆ initializeObject()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::initializeObject ( )

Initializes the redis backend

Exceptions
Exception‪if access to redis with password is denied or if database selection fails

Definition at line 144 of file RedisBackend.php.

◆ remove()

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::remove (   $entryIdentifier)

Removes all cache entries matching the specified identifier.

Scales O(1) with number of cache entries Scales O(n) with number of tags

Parameters
string$entryIdentifier‪Specifies the cache entry to remove
Returns
‪bool TRUE if (at least) an entry could be removed or FALSE if no entry was found
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 391 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext().

◆ removeIdentifierEntriesAndRelations()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::removeIdentifierEntriesAndRelations ( array  $identifiers,
array  $tags 
)
protected

Helper method for flushByTag() Gets list of identifiers and tags and removes all relations of those tags

Scales O(1) with number of cache entries Scales O(n^2) with number of tags

Parameters
array$identifiers‪List of identifiers to remove
array$tags‪List of tags to be handled

Definition at line 505 of file RedisBackend.php.

References TYPO3\CMS\Webhooks\Message\$identifier, and TYPO3\CMS\Core\Utility\StringUtility\getUniqueId().

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\flushByTag().

◆ set()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::set (   $entryIdentifier,
  $data,
array  $tags = [],
  $lifetime = null 
)

Save data in the cache

Scales O(1) with number of cache entries Scales O(n) with number of tags

Parameters
string$entryIdentifier‪Identifier for this specific cache entry
string$data‪Data to be stored
array$tags‪Tags to associate with this cache entry
int$lifetime‪Lifetime of this cache entry in seconds. If NULL is specified, default lifetime is used. "0" means unlimited lifetime.
Exceptions

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 297 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$defaultLifetime, TYPO3\CMS\Core\Cache\Backend\RedisBackend\canBeUsedInStringContext(), and TYPO3\CMS\Core\Cache\Backend\RedisBackend\FAKED_UNLIMITED_LIFETIME.

◆ setCompression()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setCompression (   $compression)

Enable data compression

Parameters
bool$compression‪TRUE to enable compression
Exceptions

Definition at line 235 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$compression.

◆ setCompressionLevel()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setCompressionLevel (   $compressionLevel)

Set data compression level. If compression is enabled and this is not set, gzcompress default level will be used.

Parameters
int$compressionLevel‪-1 to 9: Compression level
Exceptions

Definition at line 251 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$compressionLevel.

◆ setConnectionTimeout()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setConnectionTimeout (   $connectionTimeout)

Set connection timeout. This value in seconds is used as a maximum number of seconds to wait if a connection can be established.

Parameters
int$connectionTimeout‪limit in seconds, a value greater or equal than 0
Exceptions

Definition at line 271 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$connectionTimeout.

◆ setDatabase()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setDatabase (   $database)

Setter for database number

Parameters
int$databaseDatabase
Exceptions

Definition at line 208 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$database.

◆ setHostname()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setHostname (   $hostname)

Setter for server hostname

Parameters
string$hostname‪Hostname

Definition at line 187 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$hostname.

◆ setPassword()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setPassword (   $password)

Setter for authentication password

Parameters
string$password‪Password

Definition at line 224 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$password.

◆ setPersistentConnection()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setPersistentConnection (   $persistentConnection)

Setter for persistent connection

Parameters
bool$persistentConnection

Definition at line 177 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$persistentConnection.

◆ setPort()

TYPO3\CMS\Core\Cache\Backend\RedisBackend::setPort (   $port)

Setter for server port

Parameters
int$port‪Port

Definition at line 197 of file RedisBackend.php.

References TYPO3\CMS\Core\Cache\Backend\RedisBackend\$port.

Member Data Documentation

◆ $compression

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::$compression = false
protected

Indicates whether data is compressed or not (requires php zlib)

Definition at line 110 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setCompression().

◆ $compressionLevel

int TYPO3\CMS\Core\Cache\Backend\RedisBackend::$compressionLevel = -1
protected

-1 to 9, indicates zlib compression level: -1 = default level 6, 0 = no compression, 9 maximum compression

Definition at line 116 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setCompressionLevel().

◆ $connected

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::$connected = false
protected

Indicates whether the server is connected

Definition at line 74 of file RedisBackend.php.

◆ $connectionTimeout

int TYPO3\CMS\Core\Cache\Backend\RedisBackend::$connectionTimeout = 0
protected

limit in seconds (default is 0 meaning unlimited)

Definition at line 122 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setConnectionTimeout().

◆ $database

int TYPO3\CMS\Core\Cache\Backend\RedisBackend::$database = 0
protected

Number of selected database, defaults to 0

Definition at line 98 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setDatabase().

◆ $hostname

string TYPO3\CMS\Core\Cache\Backend\RedisBackend::$hostname = '127.0.0.1'
protected

Hostname / IP of the Redis server, defaults to 127.0.0.1.

Definition at line 86 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setHostname().

◆ $password

string TYPO3\CMS\Core\Cache\Backend\RedisBackend::$password = ''
protected

Password for redis authentication

Definition at line 104 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setPassword().

◆ $persistentConnection

bool TYPO3\CMS\Core\Cache\Backend\RedisBackend::$persistentConnection = false
protected

Persistent connection

Definition at line 80 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setPersistentConnection().

◆ $port

int TYPO3\CMS\Core\Cache\Backend\RedisBackend::$port = 6379
protected

Port of the Redis server, defaults to 6379

Definition at line 92 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\setPort().

◆ $redis

Redis TYPO3\CMS\Core\Cache\Backend\RedisBackend::$redis
protected

Instance of the PHP redis class

Definition at line 68 of file RedisBackend.php.

◆ FAKED_UNLIMITED_LIFETIME

const TYPO3\CMS\Core\Cache\Backend\RedisBackend::FAKED_UNLIMITED_LIFETIME = 31536000

Definition at line 45 of file RedisBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\RedisBackend\set().

◆ IDENTIFIER_DATA_PREFIX

const TYPO3\CMS\Core\Cache\Backend\RedisBackend::IDENTIFIER_DATA_PREFIX = 'identData:'

Definition at line 51 of file RedisBackend.php.

◆ IDENTIFIER_TAGS_PREFIX

const TYPO3\CMS\Core\Cache\Backend\RedisBackend::IDENTIFIER_TAGS_PREFIX = 'identTags:'

Definition at line 57 of file RedisBackend.php.

◆ TAG_IDENTIFIERS_PREFIX

const TYPO3\CMS\Core\Cache\Backend\RedisBackend::TAG_IDENTIFIERS_PREFIX = 'tagIdents:'

Definition at line 63 of file RedisBackend.php.