Put
class Put
Store an item in the cache with tags support.
This operation creates:
- The cache key with TTL
- A reverse index SET tracking which tags this key belongs to
- 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
Create a new put with tags operation instance.
Execute the put operation.
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.
at line 48
bool
execute(string $key, mixed $value, int $seconds, array $tags)
Execute the put operation.
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