In Redis, we can use the SMISMEMBER command to find out whether one or more members are in a given set. It’s similar to the SISMEMBER command, except that it allows us to check more than one member at a time.
The SMISMEMBER command was introduced in Redis 6.2.0.
Syntax
The syntax goes like this:
SMISMEMBER key member [member ...]
Example
Suppose we create the following set:
SADD animals Cat Dog Mouse Horse Zebra
We can use the SMISMEMBER command to find out whether our set contains one or more specified values:
SMISMEMBER animals Dog Zebra Cow
Result:
1) (integer) 1 2) (integer) 1 3) (integer) 0
The command returns an array reply which represents the membership of the given elements, in the same order as they are requested. When the set contains the member, SMISMEMBER returns 1, otherwise it returns 0. We can see in the above example that the set contains the first two values but not the last one.
When we change the case of an argument, we can get a different result:
SMISMEMBER animals dog Zebra Cow
Result:
1) (integer) 0 2) (integer) 1 3) (integer) 0
Non-Existent Key
Here’s what happens when I pass a key that doesn’t exist:
SMISMEMBER oops Dog Zebra Cow
Result:
1) (integer) 0 2) (integer) 0 3) (integer) 0
Passing the Wrong Number of Arguments
Passing the wrong number of arguments results in an error:
SMISMEMBER animals
Result:
(error) ERR wrong number of arguments for 'smismember' command