touch
TOUCH
Update last access time to now
Usage: touch key [type].
📍 type is one of string/list/set/zset/hash/stream.
type was added in ent811. Use it.
TOUCH sets the last access time to the current time.
You can check last access time with
OBJECT idletime key or
DEBUG object key.
This command is related to the Redis maxmemory policy.
Among the six maxmemory-policy parameters, volatile-lru and allkeys-lru
evict keys with the LRU (Least Recently Used) algorithm, starting from keys with the oldest access time.
To keep a key from being evicted as long as possible, use TOUCH to refresh its last access time.
Through Redis 3.2.0,
TTL key or
TYPE key also updated last access time.
From 3.2.1 those commands no longer do that, and TOUCH was added for this purpose.
GET key also updates access time,
but using GET only to refresh idle time loads the server and client, so use TOUCH.
A missing key is ignored and does not raise an error.
The return value is the number of keys that were touched.
See a short note on maxmemory policy (MAXMEMORY POLICY) here.
Example
| Command> | set key value |
| Result> | 1 |
| Command> | object idletime key string |
| Result> | 5 |
| Command> | touch key string |
| Result> | 1 |
| Command> | object idletime key string |
| Result> | 2 |
Syntax
TOUCH key [key ...] [type]
- Available since version 3.2.1.
- Time complexity is O(N), where N is the number of keys.
- ent811: type argument added.