class StoreContext

Mode-aware context for Redis cache operations.

Constants

MAX_EXPIRY

The maximum expiry timestamp (Year 9999) for "forever" items.

Used in the tag registry to represent items with no expiration.

TAG_FIELD_VALUE

The value stored in tag hash fields.

We only need to track membership, so we use a minimal placeholder value.

Methods

__construct(Factory $redis, string $connectionName, string $prefix, TagMode $tagMode)

Create a new store context instance.

string
prefix()

Get the cache key prefix.

string
connectionName()

Get the connection name.

TagMode
tagMode()

Get the tag mode.

int
expirationScore(int $seconds)

Get the tag membership score for a cache lifetime.

string
tagId(string $tag)

Get the tag identifier (without cache prefix).

string
tagHashKey(string $tag)

Get the full tag hash key for a given tag.

string
tagHashSuffix()

Get the tag hash suffix (for Lua scripts that build keys dynamically).

string
tagScanPattern()

Get the SCAN pattern for finding all tag sorted sets.

string
reverseIndexKey(string $key)

Get the full reverse index key for a cache key.

string
registryKey()

Get the tag registry key (without OPT_PREFIX).

mixed
withConnection(callable $callback, bool $transform = false)

Execute callback with a held connection from the pool.

bool
isCluster()

Check if the connection is a Redis Cluster.

string
optPrefix(RedisConnection $connection)

Get the OPT_PREFIX value from the Redis client.

string
fullTagPrefix(RedisConnection $connection)

Get the full tag prefix including OPT_PREFIX (for Lua scripts).

string
fullRegistryKey(RedisConnection $connection)

Get the full registry key including OPT_PREFIX (for Lua scripts).

Details

at line 35
__construct(Factory $redis, string $connectionName, string $prefix, TagMode $tagMode)

Create a new store context instance.

Parameters

Factory $redis
string $connectionName
string $prefix
TagMode $tagMode

at line 47
string prefix()

Get the cache key prefix.

Return Value

string

at line 55
string connectionName()

Get the connection name.

Return Value

string

at line 63
TagMode tagMode()

Get the tag mode.

Return Value

TagMode

at line 71
int expirationScore(int $seconds)

Get the tag membership score for a cache lifetime.

Parameters

int $seconds

Return Value

int

at line 82
string tagId(string $tag)

Get the tag identifier (without cache prefix).

Used by all mode for namespace computation (xxh128 of tag IDs in requested order). Format: "_any:tag:{tagName}:entries" or "_all:tag:{tagName}:entries"

Parameters

string $tag

Return Value

string

at line 92
string tagHashKey(string $tag)

Get the full tag hash key for a given tag.

Format: "{prefix}_any:tag:{tagName}:entries" or "{prefix}_all:tag:{tagName}:entries"

Parameters

string $tag

Return Value

string

at line 100
string tagHashSuffix()

Get the tag hash suffix (for Lua scripts that build keys dynamically).

Return Value

string

at line 110
string tagScanPattern()

Get the SCAN pattern for finding all tag sorted sets.

Format: "{prefix}_any:tag::entries" or "{prefix}_all:tag::entries"

Return Value

string

at line 120
string reverseIndexKey(string $key)

Get the full reverse index key for a cache key.

Format: "{prefix}{cacheKey}:_any:tags" or "{prefix}{cacheKey}:_all:tags"

Parameters

string $key

Return Value

string

at line 130
string registryKey()

Get the tag registry key (without OPT_PREFIX).

Format: "{prefix}_any:tag:registry" or "{prefix}_all:tag:registry"

Return Value

string

at line 146
mixed withConnection(callable $callback, bool $transform = false)

Execute callback with a held connection from the pool.

Delegates to Redis::withConnection() for context awareness (respects active pipeline/multi connections). Cache operations use raw phpredis behavior unless they explicitly request Laravel-style transforms.

Parameters

callable $callback
bool $transform

Return Value

mixed

at line 156
bool isCluster()

Check if the connection is a Redis Cluster.

Return Value

bool

at line 166
string optPrefix(RedisConnection $connection)

Get the OPT_PREFIX value from the Redis client.

Parameters

RedisConnection $connection

Return Value

string

at line 177
string fullTagPrefix(RedisConnection $connection)

Get the full tag prefix including OPT_PREFIX (for Lua scripts).

Format: "{optPrefix}{prefix}_any:tag:" or "{optPrefix}{prefix}_all:tag:"

Parameters

RedisConnection $connection

Return Value

string

at line 185
string fullRegistryKey(RedisConnection $connection)

Get the full registry key including OPT_PREFIX (for Lua scripts).

Parameters

RedisConnection $connection

Return Value

string