Fix: “ERR wrong number of arguments for ‘smismember’ command” in Redis

If you’re getting an error that reads “ERR wrong number of arguments for ‘smismember’ command” in Redis, it’s because you’re calling the SMISMEMBER command with the wrong number of arguments.

To fix this issue, make sure you’re passing the correct number of arguments. This command accepts two or more arguments, which represents a key and one or more members to check against that key.

Example of Error

Here’s an example of code that produces the above error:

SMISMEMBER animals

Result:

(error) ERR wrong number of arguments for 'smismember' command

In this case, I only passed one argument, but I should have passed two or more.

We get the same error when we call the command without any arguments at all:

SMISMEMBER

Result:

(error) ERR wrong number of arguments for 'smismember' command

Solution

To fix the issue, simply pass the correct number of arguments.

Example:

SMISMEMBER animals Cat

Result:

1) (integer) 1

Here, I provided two arguments and we got the desired result without error.

As mentioned, we can pass two or more arguments, so the following code also works without error:

SMISMEMBER animals Cat Horse Ant

Result:

1) (integer) 1
2) (integer) 1
3) (integer) 0

The command returns 1 or 0 depending on whether the member exists in the set.