Cache access tracking
Refresh recency for cached entries while leaving their values unchanged.
Redis · Module
TOUCH updates the last-access time of each supplied key that exists and returns how many supplied keys were found. It does not alter key values.
TOUCH updates the last-access time for each named key that exists, without changing its value. It returns how many supplied keys were found and touched; the operation costs O(N), where N is the number of keys listed.
TOUCH key [key ...]| Name | Type | Description |
|---|---|---|
key | key [key ...] | One or more key names whose access times should be updated when the keys exist. |
Integer reply: the number of supplied keys that exist after their last-access times are updated.
SET session:42 active
TOUCH session:42 missing:keyRefreshes the access time for the existing session key; the command returns 1 because only one of the two keys exists.
Refresh recency for cached entries while leaving their values unchanged.
Touch several potentially present keys and use the count to measure partial existence.
Keep selected keys active for LRU/LFU-oriented access accounting.
TOUCH refreshes the last-access time of every supplied key that exists and returns the count of those existing keys. It does not modify the stored values.
Follow-up: What is its complexity? O(N), where N is the number of keys supplied for touching.
The command accepts one or more key names using the syntax TOUCH key [key ...]. The integer result is the number of supplied keys that exist.
Follow-up: How would a caller detect partial success? Compare the returned count with the number of keys sent.
TOUCH has linear complexity in the number of keys it processes: O(N). This matters when a request contains many key names.
Follow-up: What design response follows from that complexity? Keep batches appropriately sized when access-time refreshes are performed at scale.
EXISTSTTLEXPIRECLIENT NO-TOUCH