Fix: “ERR Number of keys can’t be greater than number of args” when using the SINTERCARD Command in Redis

If you’re getting an error that reads “ERR Number of keys can’t be greater than number of args” when using the SINTERCARD command, it’s probably because your first argument is the wrong value.

To fix this issue, make sure the first argument reflects the number of sets that you’re comparing.

Example of Error

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

SINTERCARD 4 set1 set2 set3

Result:

(error) ERR Number of keys can't be greater than number of args

In this case the first argument is 4, but I only provided three sets.

Solution

To solve this issue, we simply need to ensure that our first argument reflects the actual number of keys that we’re comparing:

SINTERCARD 3 set1 set2 set3

Result:

(integer) 2

Here I changed the 4 to 3, and we got the desired result without error. The 3 reflects the actual number of sets that I passed.