Redis "ERR syntax error" occurs when a command violates the Redis Serialization Protocol (RESP) format or uses incorrect command syntax. This typically happens with malformed commands, wrong argument counts, or protocol violations.
Redis "ERR syntax error" is raised by the Redis server when it receives a command that violates RESP (Redis Serialization Protocol) syntax rules. This is not a logical error—it's a protocol parsing error that occurs before command execution. The error indicates that the client sent malformed data, used incorrect argument counts, sent commands in the wrong format, or violated protocol structure. RESP is a line-based protocol where each command must follow strict formatting: commands are arrays of bulk strings, terminated with CRLF (carriage return + line feed), with specific type bytes (+, -, :, $, *) indicating data types.
Test the failing command directly in redis-cli to isolate the issue:
redis-cli
127.0.0.1:6379> SET mykey "hello world"
OK
127.0.0.1:6379> GET mykey
"hello world"If the command works in redis-cli but fails in your application, the issue is with how your client library sends the command, not with Redis itself.
Verify you're sending the correct number of arguments. Check the Redis command documentation:
# WRONG: SET requires exactly 2 args (key, value)
SET mykey
# CORRECT
SET mykey "myvalue"
# WRONG: GET requires exactly 1 arg
GET key1 key2
# CORRECT
GET key1Use COMMAND INFO command-name in redis-cli to see exact argument requirements.
In RESP protocol, arguments with spaces must be properly formatted as bulk strings:
# Wrong (spaces without encoding)
SET mykey hello world
# Correct RESP2 format
*3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$11\r\nhello world\r\n
# Using redis-cli with proper quoting
SET mykey "hello world"Most client libraries handle this automatically, but if using raw socket connections, ensure proper bulk string encoding.
Outdated client libraries may have RESP protocol bugs. Update to the latest stable version:
# Node.js
npm update redis
# Python
pip install --upgrade redis
# Ruby
gem update redis
# Java
# Update Jedis or Lettuce in pom.xml/build.gradleCheck the client library changelog for syntax error fixes and protocol improvements.
If using Redis 6.0+, ensure your client supports the same RESP version:
# Check Redis RESP version support
redis-cli HELLO 3
# In your client, explicitly set RESP version if needed
# Node.js example:
const redis = require('redis');
const client = redis.createClient({
socket: { host: 'localhost', port: 6379 },
protocol: 'resp2', // or 'resp3'
});Most clients default to RESP2 for compatibility with older Redis versions.
Use Redis MONITOR to see exactly what your client is sending:
# Terminal 1: Start monitoring
redis-cli MONITOR
# Terminal 2: Run your client code
# Watch Terminal 1 output to see the exact command format sentThis reveals if your client is sending malformed RESP. Look for:
- Missing type markers ($, *, etc.)
- Incorrect length specifications
- Missing CRLF terminators
- Non-printable or unexpected characters
If only some commands fail, the connection may be in a bad state:
# Test basic connectivity
redis-cli PING
# If using connection pools, try disconnecting and reconnecting
# If using Lua scripts, ensure they're not corrupting stateClose and reopen connections. If the issue persists after reconnecting, it's not a connection state problem.
When dealing with binary data or reading from files, ensure proper encoding:
# Node.js: Ensure buffers are properly handled
const key = 'mykey';
const value = Buffer.from('hello\x00world'); // Binary data
await client.set(key, value);
# Python: Use bytes for binary data
import redis
r = redis.Redis(decode_responses=False) # Binary mode
r.set(b'mykey', b'hello\x00world')If reading from files, avoid extra whitespace or hidden characters. Use xxd or od to inspect raw bytes.
RESP protocol is line-based and sensitive to exact formatting. Each element must be preceded by a type byte: "$" for bulk strings (including length), "*" for arrays (including count), "+" for simple strings, "-" for errors, ":" for integers. All elements end with CRLF ("\r\n"). When building raw RESP manually, any deviation causes syntax errors. Connection pooling can mask state issues—if one client corrupts state, others in the pool may fail. For Lua scripting, ensure all RESP protocol handling is correct within the script. In microservices or load-balanced setups, verify all clients and Redis versions are compatible. Protocol debugging with MONITOR is invaluable but has performance impact—use only in development.
ERR Unbalanced XREAD list of streams
How to fix "ERR Unbalanced XREAD list" in Redis
ERR syntax error
How to fix "ERR syntax error" 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