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.
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.
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.
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.
ERR Unbalanced XREAD list of streams
How to fix "ERR Unbalanced XREAD list" in Redis
ConnectionError: Error while reading from socket
ConnectionError: Error while reading from socket in redis-py
ERR unknown command
How to fix ERR unknown command in Redis
Command timed out
How to fix 'Command timed out' in ioredis
ERR DISCARD without MULTI
How to fix "ERR DISCARD without MULTI" in Redis