class Add

Store an item in the cache if it doesn't exist (non-tagged).

Uses Redis SET with NX (only set if Not eXists) and EX (expiration) flags for atomic "add if not exists" semantics without requiring Lua scripts.

Methods

__construct(StoreContext $context, Serialization $serialization)

Create a new add operation instance.

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

Execute the add operation.

Details

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

Create a new add operation instance.

Parameters

StoreContext $context
Serialization $serialization

at line 36
bool execute(string $key, mixed $value, int $seconds)

Execute the add 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)

Return Value

bool

True if item was added, false if it already exists or on failure