How to fix ERR wrong number of arguments in Redis
This error occurs when a Redis command receives an incorrect number of arguments. Each Redis command has specific argument requirements, and supplying too few or too many arguments triggers this validation error.
Quick fix
Fixes ERR wrong number of arguments
help <commandname>- Identify which command is failing
- Check the command documentation
- Count your arguments carefully
- Fix your command syntax
help <commandname>ERR wrong number of arguments
What this error means
Redis enforces strict argument validation for all commands. Every command has a defined arity—the exact number or minimum number of arguments it expects. When your command doesn't match these requirements, Redis rejects it with 'ERR wrong number of arguments' and includes the command name in the error message (e.g., 'ERR wrong number of arguments for set command'). This is a syntax error that prevents the command from executing at all.
Typical symptoms
- Redis commands fail immediately with error message naming the specific command
- Transactions halt at EXEC phase when a command has wrong argument count
- Client libraries may wrap the error or display it differently depending on language
- Scripts using redis-cli fail or hang waiting for response
Common causes
- Forgetting required arguments (e.g., SET key without value)
- Providing too many arguments for a command that expects a fixed count
- Unintended quotes or escape characters changing argument count
- Using old client library versions with incompatible syntax
- Misunderstanding command arity in transactions or pipelined commands
How to fix "ERR wrong number of arguments"
Look at your error message—it should specify the command name. For example, 'ERR wrong number of arguments for set command' tells you it's the SET command.
Use redis-cli to look up the correct syntax. You can use:
help <commandname>For example, help set will show the exact format and required vs optional arguments.
Or use the COMMAND INFO subcommand:
COMMAND INFO setRemember that in Redis command syntax:
- GET requires exactly 1 argument: GET key
- MGET accepts multiple arguments: MGET key1 [key2] [key3]...
- SET requires at least 2 arguments: SET key value [EX|PX|EXAT|PXAT] [NX|XX]
Note: Command arity counts include the command name itself in the specification.
Adjust your command to match the documented format. Common fixes:
Missing value in SET:
// Wrong
SET mykey
// Correct
SET mykey myvalueExtra arguments in GET:
// Wrong
GET mykey extra_arg
// Correct
GET mykeyWrong HSET format (if using older Redis):
// Redis 3.0.0+ (multiple field-value pairs)
HSET myhash field1 value1 field2 value2
// Redis < 3.0.0 (one field-value pair only)
HSET myhash field1 value1If you're using a Redis client library (node-redis, redis-py, Predis, etc.), ensure it's up-to-date. Older versions may have different argument handling:
# Node.js
npm list redis
# Python
pip show redisUpgrade if you're on a very old version, as newer versions handle commands more correctly.
If you're using a client library, test your exact command syntax in redis-cli first to isolate the issue:
redis-cli
127.0.0.1:6379> SET mykey myvalue
OK
127.0.0.1:6379> GET mykey
"myvalue"Once it works in redis-cli, the syntax is correct and the issue is likely in how you're passing arguments from your code.
Advanced notes
Command arity is defined as: positive integer = fixed number of arguments required; negative integer = minimum number of arguments. For example, GET has arity 2 (command + key), MGET has arity -2 (command + at least one key). During MULTI/EXEC transactions, syntax errors like wrong argument count are caught during MULTI phase and cause the entire transaction to be aborted—the bad command is never queued. In Lua scripts, incorrect argument counts trigger the same error when EVALSHA or EVAL are called with mismatched scripts and arguments.
Frequently asked questions
- What does "ERR wrong number of arguments" mean?
- Redis enforces strict argument validation for all commands. Every command has a defined arity—the exact number or minimum number of arguments it expects. , 'ERR wrong number of arguments for set command').
- How do I fix "ERR wrong number of arguments"?
- This error occurs when a Redis command receives an incorrect number of arguments. Each Redis command has specific argument requirements, and supplying too few or too many arguments triggers this validation error.
- What causes "ERR wrong number of arguments"?
- Forgetting required arguments (e.g., SET key without value) Providing too many arguments for a command that expects a fixed count Unintended quotes or escape characters changing argument count
- Is the "ERR wrong number of arguments" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Redis Official Documentation
- 📖Redis Error Handling(Official Docs)