This is a preview of PR #762, not valkey.io.

SISMEMBER

Usage:
SISMEMBER key member [ XX ]
Complexity:
O(1)
Since:
1.0.0
ACL Categories:
@fast, @read, @set

Returns if member is a member of the set stored at key.

By default, a missing key is treated as an empty set, so SISMEMBER returns 0 both when the key does not exist and when the set does not contain member. The XX option tells these two cases apart: with XX, SISMEMBER returns -1 when the key does not exist.

Options#

  • XX -- Return -1 instead of 0 when key does not exist.

Reply#

One of the following:

  • Integer: 1 if the element is a member of the set.
  • Integer: 0 if the element is not a member of the set, or when the key does not exist and XX was not given.
  • Integer: -1 if the key does not exist and XX was given.

Examples#

127.0.0.1:6379> SADD myset "one"
(integer) 1
127.0.0.1:6379> SISMEMBER myset "one"
(integer) 1
127.0.0.1:6379> SISMEMBER myset "two"
(integer) 0
127.0.0.1:6379> SISMEMBER myset "two" XX
(integer) 0
127.0.0.1:6379> SISMEMBER nosuchset "one"
(integer) 0
127.0.0.1:6379> SISMEMBER nosuchset "one" XX
(integer) -1

History#

Version Change
9.2.0

Added the XX option.