Redis Command to RESP

Type commands as you would in redis-cli and get the RESP bytes that go on the wire. Useful for writing a client, for building a test fixture, and for working out why a command with quotes is not doing what you expected.

Paste below, or drop a file anywhere on this panel

Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.

The answer appears here

Paste on the left and press Encode. Nothing leaves this tab.

Examples

Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.

Quoted argument

A value containing a space is one argument, and the byte count reflects it

SET greeting "hello world"

Unclosed quote

The quoting mistake behind most wrong number of arguments errors

SET greeting "hello world

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Leaving a value with spaces unquoted

    `SET k hello world` is four arguments and an error. redis-cli splits on whitespace outside quotes, which is where wrong number of arguments comes from.

    Instead:Quote it: `SET k "hello world"`.

  2. Using the inline command form in a client

    It cannot carry a value containing a space, a newline or a null byte, and it cannot express an empty argument. It exists for telnet, not for clients.

    Instead:Send the array-of-bulk-strings form, which has none of those limits.

A client always sends an array of bulk strings

Whatever the reply will look like, the request is uniform: an array whose elements are the command name and its arguments, each as a length-prefixed bulk string. There is no separate syntax for different commands.

Why not the inline form

Redis does accept a plain whitespace-delimited line, which is how you can talk to it over telnet. No client uses it, because an inline command cannot carry a value containing a space, a newline or a null byte, and it has no way to express an empty argument. The array form has none of those limits.

Quoting decides the argument count

SET k hello world is four arguments and an error; SET k "hello world" is three and works. redis-cli splits on whitespace outside quotes, honours single and double quotes, and processes backslash escapes inside double quotes only. Getting this wrong is the usual cause of a wrong number of arguments error.

The byte count is the cost

Every command carries roughly fourteen bytes of framing plus the length prefix of each argument. For large values that is noise, but for a pipeline of small commands it is most of the traffic, which is the real argument for MSET over repeated SET and for pipelining over round trips.

Command names are case insensitive, keys are not

set and SET are the same command. mykey and MyKey are two different keys. This bites hardest when a config file or an environment variable changes case somewhere in a deployment pipeline.

What this cannot see

It does not validate the command. An unknown command, a wrong argument count for a real command, or a key of the wrong type all encode perfectly here and fail at the server. It also does not know your server version, so it cannot say whether a command exists yet.