How to fix ERR syntax error in Redis
This error occurs when Redis receives a malformed or invalid command. Common causes include incorrect command syntax, wrong number of arguments, or using a command unsupported in your Redis version. Verify your command syntax matches the Redis documentation.
Quick fix
Fixes ERR syntax error
# Example: SET command syntax
SET key value [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL] [NX|XX] [GET]- Verify command syntax in Redis documentation
- Check Redis server version
- Validate argument count and types
- Check TTL/expiration syntax in SET commands
# Example: SET command syntaxSET key value [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL] [NX|XX] [GET]ERR syntax error
What this error means
The "ERR syntax error" is returned by the Redis server when it cannot parse or understand the command you sent. This happens when the command structure violates Redis protocol rules—such as incorrect argument count, invalid command name, or unsupported options. Redis is strict about command formatting, so even small deviations cause this error. It's a programming error in your code rather than a runtime issue, indicating a bug in how you're constructing Redis commands.
Typical symptoms
- Redis commands return "ERR syntax error" response
- Node.js/client libraries throw ReplyError or ResponseError with syntax error message
- Commands fail immediately without retrying or queuing
- Using SET, GET, SPOP, HRANDFIELD, or other commands fails with syntax error
- Error occurs after upgrading Redis server to a newer version
Common causes
- Incorrect number of arguments passed to a command
- Using command options or flags not supported in your Redis server version
- Typo in command name or option names
- Passing arguments in wrong order or format
- Using string values where numbers are expected
- Incorrect TTL or timeout syntax (e.g., missing EX/PX keywords)
How to fix "ERR syntax error"
Open the official Redis documentation for the command you're using. Check the exact argument order and format required.
# Example: SET command syntax
SET key value [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL] [NX|XX] [GET]Ensure your code matches this exact format.
Some commands and options are only available in newer Redis versions. Verify your server version supports the command and options you're using.
redis-cli
> INFO serverLook for the redis_version field and cross-reference with the command documentation to confirm compatibility.
Count the arguments you're passing and ensure they match Redis command requirements. For example, the INCR command takes exactly one argument (the key).
// Wrong: INCR with too many arguments
await client.incr('counter', 'extra'); // ERR syntax error
// Correct: INCR with one argument
await client.incr('counter');When setting TTL, use proper syntax with EX (seconds) or PX (milliseconds) keywords.
// Wrong: third positional argument
await client.set('key', 'value', 3600); // ERR syntax error
// Correct: EX keyword with TTL
await client.set('key', 'value', { EX: 3600 });
// Also correct with node-redis v4+ syntax
await client.setEx('key', 3600, 'value');Test your command in redis-cli to isolate the syntax issue from client code.
redis-cli
> SET mykey "myvalue" EX 3600
OKIf the command works in redis-cli but fails in your code, the issue is in how you're constructing the command in your client library.
If the issue persists, monitor the actual commands sent to Redis to see what's being transmitted.
redis-cli
> MONITORThen run your code and watch what commands appear. Compare them against Redis documentation to spot the syntax error. Be aware MONITOR reduces performance, so use it only for debugging.
Advanced notes
Thread safety issues in Jedis and other multi-threaded clients can cause syntax errors. If using a Redis client in a multi-threaded environment, ensure you're using thread-safe pooling or separate client instances per thread. Some commands like KEEPTTL and HRANDFIELD are only available in Redis 6.2+, causing syntax errors on older versions. Version-gate your code or upgrade Redis if needed. The COMMAND DOCS command (Redis 7.0+) provides detailed syntax information: use redis-cli "COMMAND DOCS SET" to see full documentation for any command.
Frequently asked questions
- What does "ERR syntax error" mean?
- The "ERR syntax error" is returned by the Redis server when it cannot parse or understand the command you sent. This happens when the command structure violates Redis protocol rules—such as incorrect argument count, invalid command name, or unsupported options. Redis is strict about command formatting, so even small deviations cause this error.
- How do I fix "ERR syntax error"?
- This error occurs when Redis receives a malformed or invalid command. Common causes include incorrect command syntax, wrong number of arguments, or using a command unsupported in your Redis version. Verify your command syntax matches the Redis documentation.
- What causes "ERR syntax error"?
- Incorrect number of arguments passed to a command Using command options or flags not supported in your Redis server version Typo in command name or option names
- Is the "ERR syntax error" 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 Docs - Error Handling(Official Docs)
- 📖Redis Docs - Redis CLI(Official Docs)
- 📖Redis Docs - COMMAND DOCS Reference(Official Docs)
- 🐙