Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

CLIENT CACHING

Last updated
CLIENT CACHING YES | NO
Group
Connection
Complexity
O(1)
Arity
3 (exactly, counting the command name)
HotKV Cloud
All plans
On-Premise
no license needed

With CLIENT TRACKING in OPTIN or OPTOUT mode, the connection decides command by command which keys are tracked. CLIENT CACHING YES turns tracking on for the keys of the next command, in OPTIN mode, where nothing is tracked otherwise. CLIENT CACHING NO leaves the keys of the next command out, in OPTOUT mode, where everything is tracked otherwise.

The choice covers the next command only. When it is sent before MULTI, it covers the commands queued up to EXEC. It can also be queued inside the transaction.

Simple string OK, in RESP2 and RESP3.

Errors:

Error Cause
ERR CLIENT CACHING can be called only when the client is in tracking mode with OPTIN or OPTOUT mode enabled Tracking is off.
ERR CLIENT CACHING YES is only valid when tracking is enabled in OPTIN mode. YES, with tracking on in another mode.
ERR CLIENT CACHING NO is only valid when tracking is enabled in OPTOUT mode. NO, with tracking on in another mode.
ERR syntax error The argument is neither YES nor NO.
ERR wrong number of arguments for 'client|caching' command The argument is missing or there are more than one.
127.0.0.1:6379> CLIENT CACHING YES
(error) ERR CLIENT CACHING can be called only when the client is in tracking mode with OPTIN or OPTOUT mode enabled
127.0.0.1:6379> CLIENT TRACKING ON OPTIN
OK
127.0.0.1:6379> CLIENT CACHING NO
(error) ERR CLIENT CACHING NO is only valid when tracking is enabled in OPTOUT mode.
127.0.0.1:6379> CLIENT CACHING YES
OK
127.0.0.1:6379> CLIENT TRACKINGINFO
1) "flags"
2) 1) "on"
2) "optin"
3) "caching-yes"
3) "redirect"
4) (integer) 0
5) "prefixes"
6) (empty array)

caching-yes (or caching-no in OPTOUT mode) shows in CLIENT TRACKINGINFO until the next command has run.

The replies and error texts follow Redis 8 and Valkey 9.

CLIENT TRACKING, CLIENT TRACKINGINFO, Client-side caching