What it means
Every Redis command takes a fixed number of arguments, or at least a minimum: GET takes exactly
one key, SET at least a key and a value, HSET a key and then field-value pairs. Redis checks the
count before anything else, and if it’s wrong it refuses the command, naming it in lower case:
(error) ERR wrong number of arguments for 'set' command
Nothing ran. For a subcommand the name has a | in it: CONFIG GET with nothing to get is
'config|get'.
The count is of what reached the server, not what you typed. A variable that turned out empty, a list that was empty, or a value that was split in two all change it, which is why the command often looks right in your code.
Close relatives:
- The count is right but the words aren’t: an unknown option, or a value split by a space, is usually ERR syntax error instead.
- Inside a Lua script,
redis.call('GET')fails withERR Wrong number of args calling Redis command from script(Valkey:Wrong number of args calling command from script). - Inside a transaction, the command is refused as you queue it and
EXECdiscards everything (EXECABORT).
Common causes
- An empty value that disappeared. In a shell,
redis-cli SET user:1 $NAMEwithNAMEempty sends onlySET user:1. The same happens in code that builds the argument list and leaves out empty strings ornulls. - An empty list spread into a variadic command.
MGET,DEL,SADD,LPUSH,HSETandZADDneed at least one key or element. Called with an empty array of keys or elements, a client can send the command name alone. - An odd number of field-value pairs.
MSET k1 v1 k2,HSET h f1 v1 f2, or a dictionary flattened with one value missing. - A missing key name, often from a key built out of a variable that was empty.
- Text from another database:
SELECT * FROM usersis Redis’sSELECT(switch database), which takes one argument.
How to fix it
See what was actually sent
Check the command’s shape with COMMAND DOCS <name> (its arguments), or COMMAND INFO <name>,
whose second field is the arity: a positive number is the exact count including the command
name, a negative one is the minimum (set is -3: at least a key and a value).
On a server you control, MONITOR prints every command as it arrives, with each argument quoted,
so a missing or split argument is visible. It slows a busy server down: run it briefly, not on a
loaded production server.
Quote values in the shell
redis-cli SET user:1 "$NAME" # an empty NAME becomes "", not nothing
redis-cli HSET user:1 name "Ada Lovelace"
Quoting keeps an empty value as an empty string (a valid value) and keeps a value with spaces in one piece.
Don’t send variadic commands with nothing in them
Check the list before the call: if there are no keys, skip the MGET or DEL; if there are no
fields, skip the HSET. For pairs, build the arguments from a map or a list of pairs rather than a
flat list you assemble by hand.
Use the right command
If you meant to run SQL, Redis isn’t the place: it has no tables or SELECT … FROM. SELECT <n>
switches the connection to database n.
Reproduce it
Redis 8.10.2 and Valkey 8.1.10 gave the same replies, in database 15:
GET
(error) ERR wrong number of arguments for 'get' command
SET seo:err:k
(error) ERR wrong number of arguments for 'set' command
HSET seo:err:h f
(error) ERR wrong number of arguments for 'hset' command
MSET seo:err:a 1 seo:err:b
(error) ERR wrong number of arguments for 'mset' command
SELECT * FROM users
(error) ERR wrong number of arguments for 'select' command
CONFIG GET
(error) ERR wrong number of arguments for 'config|get' command
SET seo:err:k ''
OK
The last line shows an empty string is a perfectly good value: it’s a missing one that fails.
DEL, LPUSH, ZADD, XADD and EVAL with too few arguments got the same error.
From a shell (sign-in options left out), with the variable empty, then set to a name with a space, then quoted:
sh -c 'redis-cli SET seo:err:user:1 $NAME' # NAME empty
sh -c 'redis-cli SET seo:err:user:1 $NAME' # NAME="Ada Lovelace"
sh -c 'redis-cli SET seo:err:user:1 "$NAME"' # NAME="Ada Lovelace"
ERR wrong number of arguments for 'set' command
ERR syntax error
OK
Unquoted, Ada Lovelace became two arguments, and SET read Lovelace as an option, hence a
syntax error rather than this one.
From a script, EVAL "return redis.call('GET')" 0:
(error) ERR Wrong number of args calling Redis command from script script: 72273adc3c5955bf8543f1ad6ce893355b89617d, on @user_script:1.
Valkey 8.1.10: ERR Wrong number of args calling command from script, then the same suffix.
In Inlet
Query tabs take redis-cli commands, one a line, and complete command names, namespaces and hash fields as you type. A value with spaces goes in quotes there as in redis-cli. When the server refuses a command, Inlet shows its message and links to this page.