EXISTS
Since 1.1.0KeysChanged in 1.2.1
Syntax
EXISTS key [key ...]History
- 1.2.1: acl categories: removed generic
Returns how many of the given keys exist. With one key the answer is 1 or 0, so it serves as a yes-or-no test.
With several keys, each is counted every time it is named: EXISTS a a is 2 when a exists. To check that every key of a list exists, name each one once and compare the count with the number of keys.
A key of any type counts, a string holding "" included. A key whose time to live has run out does not. EXISTS only asks: it does not count as a use of the key for an LRU or LFU eviction policy, and leaves the key's OBJECT IDLETIME as it was. TOUCH counts the same way and does mark the keys as used. TYPE tells a key's type as well, none for a missing one.
In a cluster, the keys must all be in one slot, or the command fails with CROSSSLOT (Cluster).
Reply
The number of keys that exist, counting repeats, as an integer.
Examples
> SET a 1
OK
> SET empty ""
OK
> EXISTS a
(integer) 1
> EXISTS a a missing
(integer) 2
> EXISTS a empty
(integer) 2
> EXISTS missing
(integer) 0