class Decrement

Decrement the value of an item in the cache with tags support.

Decrements the numeric value and adds/updates tag entries. If the key doesn't exist, creates it with negative of decrement value (no initial TTL).

Optimization: Uses Lua script to perform decrement, TTL check, and tag updates in a single network round trip (1 RTT).

Methods

__construct(StoreContext $context)

Create a new decrement with tags operation instance.

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

Execute the decrement operation.

string
decrementWithTagsScript()

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

Details

at line 24
__construct(StoreContext $context)

Create a new decrement with tags operation instance.

Parameters

StoreContext $context

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

Execute the decrement operation.

Parameters

string $key

The cache key (without prefix)

int $value

The amount to decrement by

array $tags

Array of tag names (will be cast to strings)

Return Value

int|bool

The new value after decrementing, or false on failure

at line 158
protected string decrementWithTagsScript()

Get the Lua script for decrementing 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] - Decrement amount ARGV[2] - Tag prefix for building tag hash keys ARGV[3] - Tag registry key ARGV[4] - Current timestamp ARGV[5] - Raw key (without prefix, for hash field name) ARGV[6] - Tag hash suffix (":entries") ARGV[7...] - Tag names

Return Value

string