RedisBackend
class RedisBackend extends AbstractBackend implements TaggableBackendInterface, IterableBackendInterface, FreezableBackendInterface, PhpCapableBackendInterface, WithStatusInterface (View source)
A caching backend which stores cache entries in Redis using the phpredis PHP extension.
Redis is a noSQL database with very good scaling characteristics in proportion to the amount of entries and data size.
Traits
Constants
DATETIME_EXPIRYTIME_UNLIMITED |
|
UNLIMITED_LIFETIME |
|
MIN_REDIS_VERSION |
|
Properties
protected FrontendInterface | $cache | Reference to the cache frontend which uses this backend |
from AbstractBackend |
protected string | $cacheIdentifier | from AbstractBackend | |
protected string | $identifierPrefix | A prefix to seperate stored by appliaction context and cache |
from AbstractBackend |
protected int | $defaultLifetime | Default lifetime of a cache entry in seconds |
from AbstractBackend |
protected EnvironmentConfiguration | $environmentConfiguration | from AbstractBackend | |
protected array | $_requiredEntryIdentifiers | from RequireOnceFromValueTrait | |
protected Redis | $redis | ||
protected | $frozen | ||
protected | $hostname | ||
protected | $port | ||
protected | $database | ||
protected | $password | ||
protected | $compressionLevel | ||
protected | $batchSize | Redis allows a maximum of 1024 * 1024 parameters, but we use a lower limit to prevent long blocking calls. |
Methods
Constructs this backend
No description
Sets the default lifetime for this cache backend
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
Returns the internally used, prefixed entry identifier for the given public entry identifier.
Loads PHP code from the cache and require_onces it right away.
Saves data in the cache.
Loads data from the cache.
Checks if a cache entry with the specified identifier exists.
Removes all cache entries matching the specified identifier.
Removes all cache entries of this cache
This backend does not need an externally triggered garbage collection
Removes all cache entries of this cache which are tagged by the specified tag.
Removes all cache entries of this cache which are tagged by the specified tags.
Finds and returns all cache entry identifiers which are tagged by the specified tag.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Freezes this cache backend.
Tells if this backend is frozen.
Sets the hostname or the socket of the Redis server
Sets the port of the Redis server.
Sets the database that will be used for this backend
No description
No description
Sets the Maximum number of items for batch operations
No description
No description
Details
__construct(EnvironmentConfiguration $environmentConfiguration, array $options)
Constructs this backend
protected void
setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)
No description
protected bool
setProperty(string $propertyName, mixed $propertyValue)
No description
void
setCache(FrontendInterface $cache)
Sets a reference to the cache frontend which uses this backend
void
setDefaultLifetime(int|string $defaultLifetime)
Sets the default lifetime for this cache backend
protected DateTime
calculateExpiryTime(int $lifetime = null)
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
string
getPrefixedIdentifier(string $entryIdentifier)
Returns the internally used, prefixed entry identifier for the given public entry identifier.
While Flow applications will mostly refer to the simple entry identifier, it may be necessary to know the actual identifier used by the cache backend in order to share cache entries with other applications. This method allows for retrieving it.
Note that, in case of the AbstractBackend, this method is returns just the given entry identifier.
mixed
requireOnce(string $entryIdentifier)
Loads PHP code from the cache and require_onces it right away.
void
set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)
Saves data in the cache.
mixed
get(string $entryIdentifier)
Loads data from the cache.
bool
has(string $entryIdentifier)
Checks if a cache entry with the specified identifier exists.
bool
remove(string $entryIdentifier)
Removes all cache entries matching the specified identifier.
Usually this only affects one entry but if - for what reason ever - old entries for the identifier still exist, they are removed as well.
void
flush()
Removes all cache entries of this cache
The flush method will use the EVAL command to flush all entries and tags for this cache in an atomic way.
void
collectGarbage()
This backend does not need an externally triggered garbage collection
int
flushByTag(string $tag)
Removes all cache entries of this cache which are tagged by the specified tag.
int
flushByTags(array $tags)
Removes all cache entries of this cache which are tagged by the specified tags.
array
findIdentifiersByTag(string $tag)
Finds and returns all cache entry identifiers which are tagged by the specified tag.
string|bool
current()
{@inheritdoc}
void
next()
{@inheritdoc}
string|bool
key()
{@inheritdoc}
bool
valid()
{@inheritdoc}
void
rewind()
{@inheritdoc}
void
freeze()
Freezes this cache backend.
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.
bool
isFrozen()
Tells if this backend is frozen.
void
setHostname(string $hostname)
Sets the hostname or the socket of the Redis server
void
setPort(int|string $port)
Sets the port of the Redis server.
Unused if you want to connect to a socket (i.e. hostname contains a /)
void
setDatabase(int|string $database)
Sets the database that will be used for this backend
void
setPassword(string $password)
No description
void
setCompressionLevel(int|string $compressionLevel)
No description
void
setBatchSize(int|string $batchSize)
Sets the Maximum number of items for batch operations
void
setRedis(Redis $redis = null)
No description
protected void
verifyRedisVersionIsSupported()
No description
Result
getStatus()
Validates that the configured redis backend is accessible and returns some details about its configuration if that's the case