class Add

Store an item in the cache if it doesn't exist, with tags support.

Uses Redis SET with NX flag for atomic "add if not exists" operation. Only adds tag entries if the cache key was successfully created.

Methods

__construct(StoreContext $context, Serialization $serialization)

Create a new add with tags operation instance.

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

Execute the add operation.

string
addWithTagsScript()

Get the Lua script for adding a value if it doesn't exist, with tag tracking.

Details

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

Create a new add with tags operation instance.

Parameters

StoreContext $context
Serialization $serialization

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

Execute the add operation.

Parameters

string $key

The cache key (without prefix)

mixed $value

The value to store (will be serialized)

int|null $seconds

TTL in seconds, or null for no expiration

array $tags

Array of tag names (will be cast to strings)

Return Value

bool

True if item was added, false if it already exists

at line 169
protected string addWithTagsScript()

Get the Lua script for adding a value if it doesn't exist, 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, or zero for no expiration 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