class RedisStore extends TaggableStore implements CanFlushLocks, LockProvider

Properties

protected Factory $redis
protected string $prefix

A string that should be prepended to keys.

protected string $connection

The Redis connection instance that should be used to manage locks.

protected string $lockConnection

The name of the connection that should be used for locks.

protected TagMode $tagMode

The tag mode (All or Any).

protected array|bool|null $serializableClasses

The classes that should be allowed during unserialization.

protected SerializableClassPolicy|null $serializableClassPolicy

The shared serializable class policy.

Methods

tags(mixed $names)

Begin executing a new tags operation.

bool
supportsTags()

Determine if this store currently supports tags.

TagMode
getTagMode()

Get the tag mode.

__construct(Factory $redis, string $prefix = '', string $connection = 'default', array|bool|null $serializableClasses = null, SerializableClassPolicy|null $serializableClassPolicy = null)

Create a new Redis store.

mixed
get(string $key)

Retrieve an item from the cache by key.

array
many(array $keys)

Retrieve multiple items from the cache by key.

bool
put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

bool
putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

bool
add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

bool|int
increment(string $key, int $value = 1)

Increment the value of an item in the cache.

bool|int
decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

bool
forever(string $key, mixed $value)

Store an item in the cache indefinitely.

lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

bool
touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

bool
forget(string $key)

Remove an item from the cache.

bool
flush()

Remove all items from the cache.

bool
supportsFlushingLocks()

Determine if the store can currently flush locks.

bool
flushLocks()

Remove all locks from the store.

anyTagOps()

Get the any tag operations container.

allTagOps()

Get the all tag operations container.

array|null
flushStaleTags()

Remove all expired tag set entries.

setTagMode(TagMode|string $mode)

Set the tag mode.

mixed
withPinnedConnection(callable $callback)

Pin a pool connection for the duration of a callback.

connection()

Get the Redis connection instance.

lockConnection()

Get the Redis connection instance that should be used to manage locks.

bool
hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

void
setConnection(string|null $connection)

Specify the name of the connection that should be used to store data.

setLockConnection(string $connection)

Specify the name of the connection that should be used to manage locks.

string
getPrefix()

Get the cache key prefix.

getRedis()

Get the Redis database instance.

void
setPrefix(string|null $prefix)

Set the cache key prefix.

getContext()

Get the StoreContext instance.

getSerialization()

Get the Serialization instance.

Details

at line 291
TaggedCache tags(mixed $names)

Begin executing a new tags operation.

Parameters

mixed $names

Return Value

TaggedCache

in TaggableStore at line 31
bool supportsTags()

Determine if this store currently supports tags.

Stores whose tag support depends on configuration or composition override this; for everything else extending TaggableStore, tag support is unconditional. A store that can return false here must also throw a NotSupportedException from tags() because Repository relies on the store to enforce its own conditional support.

Return Value

bool

at line 345
TagMode getTagMode()

Get the tag mode.

Return Value

TagMode

at line 111
__construct(Factory $redis, string $prefix = '', string $connection = 'default', array|bool|null $serializableClasses = null, SerializableClassPolicy|null $serializableClassPolicy = null)

Create a new Redis store.

Parameters

Factory $redis
string $prefix
string $connection
array|bool|null $serializableClasses
SerializableClassPolicy|null $serializableClassPolicy

at line 128
mixed get(string $key)

Retrieve an item from the cache by key.

Parameters

string $key

Return Value

mixed

at line 137
array many(array $keys)

Retrieve multiple items from the cache by key.

Items not found in the cache will have a null value.

Parameters

array $keys

Return Value

array

at line 145
bool put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 153
bool putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

Parameters

array $values
int $seconds

Return Value

bool

at line 161
bool add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 169
bool|int increment(string $key, int $value = 1)

Increment the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 177
bool|int decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 185
bool forever(string $key, mixed $value)

Store an item in the cache indefinitely.

Parameters

string $key
mixed $value

Return Value

bool

at line 193
Lock lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

Parameters

string $name
int $seconds
string|null $owner

Return Value

Lock

at line 201
Lock restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

Parameters

string $name
string $owner

Return Value

Lock

at line 209
bool touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

Parameters

string $key
int $seconds

Return Value

bool

at line 221
bool forget(string $key)

Remove an item from the cache.

Parameters

string $key

Return Value

bool

at line 233
bool flush()

Remove all items from the cache.

Return Value

bool

at line 241
bool supportsFlushingLocks()

Determine if the store can currently flush locks.

Return Value

bool

at line 251
bool flushLocks()

Remove all locks from the store.

Return Value

bool

Exceptions

RuntimeException

at line 267
AnyTagOperations anyTagOps()

Get the any tag operations container.

Use this to access all any-mode tagged cache operations.

Return Value

AnyTagOperations

at line 280
AllTagOperations allTagOps()

Get the all tag operations container.

Use this to access all all-mode tagged cache operations.

Return Value

AllTagOperations

at line 316
array|null flushStaleTags()

Remove all expired tag set entries.

Returns an array of snake_case stat keys with integer values, or null if no stats are available.

Return Value

array|null

at line 331
RedisStore setTagMode(TagMode|string $mode)

Set the tag mode.

Boot-only. Mutates state on a per-worker singleton; runtime mutation races across coroutines.

Parameters

TagMode|string $mode

Return Value

RedisStore

at line 356
mixed withPinnedConnection(callable $callback)

Pin a pool connection for the duration of a callback.

All Redis operations inside the callback reuse the same connection, avoiding multiple pool checkouts.

Parameters

callable $callback

Return Value

mixed

at line 364
RedisProxy connection()

Get the Redis connection instance.

Return Value

RedisProxy

at line 372
RedisProxy lockConnection()

Get the Redis connection instance that should be used to manage locks.

Return Value

RedisProxy

at line 380
bool hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

Return Value

bool

at line 392
void setConnection(string|null $connection)

Specify the name of the connection that should be used to store data.

Boot-only. Persists on the cached store for the worker lifetime and triggers cache invalidation of resolved operations; per-request use races across coroutines.

Parameters

string|null $connection

Return Value

void

at line 404
RedisStore setLockConnection(string $connection)

Specify the name of the connection that should be used to manage locks.

Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.

Parameters

string $connection

Return Value

RedisStore

at line 414
string getPrefix()

Get the cache key prefix.

Return Value

string

at line 422
Factory getRedis()

Get the Redis database instance.

Return Value

Factory

at line 434
void setPrefix(string|null $prefix)

Set the cache key prefix.

Boot-only. Persists on the cached store for the worker lifetime and triggers cache invalidation of resolved operations; per-request use races across coroutines.

Parameters

string|null $prefix

Return Value

void

at line 443
StoreContext getContext()

Get the StoreContext instance.

Return Value

StoreContext

at line 456
Serialization getSerialization()

Get the Serialization instance.

Return Value

Serialization