TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
RedisBackend Class Reference
Inheritance diagram for RedisBackend:
AbstractBackend TaggableBackendInterface BackendInterface BackendInterface

Public Member Functions

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

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 AbstractBackend
const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'
 
const UNLIMITED_LIFETIME = 0
 

Protected Member Functions

 removeIdentifierEntriesAndRelations (array $identifiers, array $tags)
 
 canBeUsedInStringContext ($variable)
 
- Protected Member Functions inherited from AbstractBackend
 calculateExpiryTime ($lifetime=null)
 

Protected Attributes

 $redis
 
 $connected = false
 
 $hostname = '127.0.0.1'
 
 $port = 6379
 
 $database = 0
 
 $password = ''
 
 $compression = false
 
 $compressionLevel = -1
 
- Protected Attributes inherited from AbstractBackend
 $cache
 
 $cacheIdentifier
 
 $context
 
 $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
http://code.google.com/p/redis/
http://github.com/owlient/phpredis

Definition at line 28 of file RedisBackend.php.

Constructor & Destructor Documentation

__construct (   $context,
array  $options = array() 
)

Construct this backend

Parameters
string$contextFLOW3's application context
array$optionsConfiguration options
Exceptions
\TYPO3\CMS\Core\Cache\Exceptionif php redis module is not loaded

Definition at line 125 of file RedisBackend.php.

References AbstractBackend\$context.

Member Function Documentation

canBeUsedInStringContext (   $variable)
protected

Helper method to catch invalid identifiers and tags

Parameters
mixed$variableVariable to be checked
Returns
bool

Definition at line 528 of file RedisBackend.php.

Referenced by RedisBackend\findIdentifiersByTag(), RedisBackend\flushByTag(), RedisBackend\get(), RedisBackend\has(), RedisBackend\remove(), and RedisBackend\set().

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)

Returns
void

Implements BackendInterface.

Definition at line 463 of file RedisBackend.php.

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$tagThe tag to search for
Returns
array An array of entries with all matching entries. An empty array if no entries matched
Exceptions
\InvalidArgumentExceptionif tag is not a string

Implements TaggableBackendInterface.

Definition at line 401 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext().

flush ( )

Removes all cache entries of this cache.

Scales O(1) with number of cache entries

Returns
void

Implements BackendInterface.

Definition at line 421 of file RedisBackend.php.

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$tagTag the entries must have
Returns
void
Exceptions
\InvalidArgumentExceptionif identifier is not a string

Implements TaggableBackendInterface.

Definition at line 439 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext(), and RedisBackend\removeIdentifierEntriesAndRelations().

get (   $entryIdentifier)

Loads data from the cache.

Scales O(1) with number of cache entries

Parameters
string$entryIdentifierAn 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
\InvalidArgumentExceptionif identifier is not a string

Implements BackendInterface.

Definition at line 324 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext().

has (   $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

Scales O(1) with number of cache entries

Parameters
string$entryIdentifierIdentifier specifying the cache entry
Returns
bool TRUE if such an entry exists, FALSE if not
Exceptions
\InvalidArgumentExceptionif identifier is not a string

Implements BackendInterface.

Definition at line 349 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext().

initializeObject ( )

Initializes the redis backend

Returns
void
Exceptions
\TYPO3\CMS\Core\Cache\Exceptionif access to redis with password is denied or if database selection fails

Definition at line 139 of file RedisBackend.php.

References port, and GeneralUtility\SYSLOG_SEVERITY_ERROR.

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$entryIdentifierSpecifies the cache entry to remove
Returns
bool TRUE if (at least) an entry could be removed or FALSE if no entry was found
Exceptions
\InvalidArgumentExceptionif identifier is not a string

Implements BackendInterface.

Definition at line 368 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext().

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$identifiersList of identifiers to remove
array$tagsList of tags to be handled
Returns
void

Definition at line 492 of file RedisBackend.php.

References StringUtility\getUniqueId().

Referenced by RedisBackend\flushByTag().

set (   $entryIdentifier,
  $data,
array  $tags = array(),
  $lifetime = null 
)

Save data in the cache

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

Parameters
string$entryIdentifierIdentifier for this specific cache entry
string$dataData to be stored
array$tagsTags to associate with this cache entry
int$lifetimeLifetime of this cache entry in seconds. If NULL is specified, default lifetime is used. "0" means unlimited lifetime.
Returns
void
Exceptions
\InvalidArgumentExceptionif identifier is not valid
\TYPO3\CMS\Core\Cache\Exception\InvalidDataExceptionif data is not a string

Implements BackendInterface.

Definition at line 271 of file RedisBackend.php.

References RedisBackend\canBeUsedInStringContext().

setCompression (   $compression)

Enable data compression

Parameters
bool$compressionTRUE to enable compression
Returns
void
Exceptions
\InvalidArgumentExceptionif compression parameter is not of type boolean

Definition at line 226 of file RedisBackend.php.

References RedisBackend\$compression.

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
Returns
void
Exceptions
\InvalidArgumentExceptionif compressionLevel parameter is not within allowed bounds

Definition at line 244 of file RedisBackend.php.

References RedisBackend\$compressionLevel.

setDatabase (   $database)

Setter for database number

Parameters
int$databaseDatabase
Returns
void
Exceptions
\InvalidArgumentExceptionif database number is not valid

Definition at line 195 of file RedisBackend.php.

References RedisBackend\$database.

setHostname (   $hostname)

Setter for server hostname

Parameters
string$hostnameHostname
Returns
void

Definition at line 170 of file RedisBackend.php.

References RedisBackend\$hostname.

setPassword (   $password)

Setter for authentication password

Parameters
string$passwordPassword
Returns
void

Definition at line 213 of file RedisBackend.php.

References RedisBackend\$password.

setPort (   $port)

Setter for server port

Parameters
int$portPort
Returns
void

Definition at line 182 of file RedisBackend.php.

References RedisBackend\$port, and port.

Member Data Documentation

$compression = false
protected

Definition at line 109 of file RedisBackend.php.

Referenced by RedisBackend\setCompression().

$compressionLevel = -1
protected

Definition at line 116 of file RedisBackend.php.

Referenced by RedisBackend\setCompressionLevel().

$connected = false
protected

Definition at line 74 of file RedisBackend.php.

$database = 0
protected

Definition at line 95 of file RedisBackend.php.

Referenced by RedisBackend\setDatabase().

$hostname = '127.0.0.1'
protected

Definition at line 81 of file RedisBackend.php.

Referenced by RedisBackend\setHostname().

$password = ''
protected

Definition at line 102 of file RedisBackend.php.

Referenced by RedisBackend\setPassword().

$port = 6379
protected

Definition at line 88 of file RedisBackend.php.

Referenced by RedisBackend\setPort().

$redis
protected

Definition at line 67 of file RedisBackend.php.

const FAKED_UNLIMITED_LIFETIME = 31536000

Definition at line 43 of file RedisBackend.php.

const IDENTIFIER_DATA_PREFIX = 'identData:'

Definition at line 49 of file RedisBackend.php.

const IDENTIFIER_TAGS_PREFIX = 'identTags:'

Definition at line 55 of file RedisBackend.php.

const TAG_IDENTIFIERS_PREFIX = 'tagIdents:'

Definition at line 61 of file RedisBackend.php.