Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Module

TOUCH

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.

How it works

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.

Syntax

TOUCH key [key ...]

Parameters

NameTypeDescription
keykey [key ...]One or more key names whose access times should be updated when the keys exist.

Returns

Integer reply: the number of supplied keys that exist after their last-access times are updated.

Key points

  • For each existing key, Redis refreshes its last-access timestamp.
  • The command requires at least one key and supports a variable-length key list.
  • The integer reply reports how many supplied names currently exist.
  • Processing cost grows linearly with the number of keys in the request.

Common mistakes

  • The result counts existing keys only, so nonexistent names contribute zero.
  • Large key lists increase work linearly; avoid treating TOUCH as a constant-time operation.

Example: Touch an active session key

SET session:42 active
TOUCH session:42 missing:key

Refreshes the access time for the existing session key; the command returns 1 because only one of the two keys exists.

When to use it

Cache access tracking

Refresh recency for cached entries while leaving their values unchanged.

Batch existence measurement

Touch several potentially present keys and use the count to measure partial existence.

Eviction-aware workflows

Keep selected keys active for LRU/LFU-oriented access accounting.

Interview questions

QWhat does Redis TOUCH do, and what does it return?

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.

QWhat is the syntax and result semantics of TOUCH?

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.

QWhat is the complexity of TOUCH?

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.

  • EXISTS
  • TTL
  • EXPIRE
  • CLIENT NO-TOUCH

Source: TOUCH | Docs. Checked 2026-10-16.