TOUCH

Since 1.1.0KeysChanged in 1.2.1

Syntax

TOUCH key [key ...]
  • Flags: fast, readonly
  • ACL categories: @fast, @keyspace, @read
  • Arity: -2

History

  • 1.2.1: acl categories: removed generic

Marks the given keys as used, and returns how many of them exist. It is for keeping keys that matter from being evicted: under an LRU maxmemory-policy, TOUCH resets each key's idle time, as a read would, without sending its value back; under an LFU one, it counts as a use. Memory explains how eviction picks keys.

Keys that do not exist, or whose time to live has run out, are skipped and not counted. A key named twice is counted twice, as in EXISTS. TOUCH does not change a key's value or its time to live. Unlike EXISTS, which only asks, TOUCH counts as a use; under a policy that does not go by use, such as the default noeviction, nothing is recorded and the two are the same.

Reply

The number of keys that exist, counting repeats, as an integer.

Examples

Under allkeys-lru:

> SET a 1
OK
> OBJECT IDLETIME a          (some seconds later)
(integer) 3
> TOUCH a missing a
(integer) 2
> OBJECT IDLETIME a
(integer) 0