class Put

Store an item in the cache with tags support.

This operation creates:

  1. The cache key with TTL
  2. A reverse index SET tracking which tags this key belongs to
  3. Hash field entries in each tag's hash with expiration using HSETEX

The reverse index is critical for proper cleanup during flush operations. Without it, flushing one tag would leave orphaned fields in other tag hashes.

Performance: Uses atomic HSETEX command (Redis 8.0+) for 30-40% reduction in Redis commands compared to HSET + HEXPIRE pattern.

Memory overhead: ~60 bytes per cached item (reverse index SET) Command count: 4 base commands + (1 x N tags) with HSETEX optimization

Methods

__construct(StoreContext $context, Serialization $serialization)

Create a new put with tags operation instance.

bool
execute(string $key, mixed $value, int $seconds, array $tags)

Execute the put operation.

string
storeWithTagsScript()

Get the Lua script for storing a value with tag tracking.

Details

at line 33
__construct(StoreContext $context, Serialization $serialization)

Create a new put with tags operation instance.

Parameters

StoreContext $context
Serialization $serialization

at line 48
bool execute(string $key, mixed $value, int $seconds, array $tags)

Execute the put operation.

Parameters

string $key

The cache key (without prefix)

mixed $value

The value to store (will be serialized)

int $seconds

TTL in seconds (must be > 0)

array $tags

Array of tag names (will be cast to strings)

Return Value

bool

True if successful, false on failure

at line 181
protected string storeWithTagsScript()

Get the Lua script for storing a value with tag tracking.

KEYS[1] - The cache key (prefixed) KEYS[2] - The reverse index key (tracks which tags this key belongs to) ARGV[1] - Serialized value ARGV[2] - TTL in seconds ARGV[3] - Tag prefix for building tag hash keys ARGV[4] - Tag registry key ARGV[5] - Current timestamp ARGV[6] - Raw key (without prefix, for hash field name) ARGV[7] - Tag hash suffix (":entries") ARGV[8...] - Tag names

Return Value

string