Skip to content

Instantly share code, notes, and snippets.

@ik5
Created February 8, 2012 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/1773844 to your computer and use it in GitHub Desktop.
Save ik5/1773844 to your computer and use it in GitHub Desktop.
Redis nested multibulk
1) 1) (integer) 0
2) (integer) 1328734844
3) (integer) 14
4) 1) "CONFIG"
2) "SET"
3) "slowlog-log-slower-than"
4) "1"
@ik5
Copy link
Author

ik5 commented Feb 8, 2012

This output is not as the original protocol at: http://redis.io/topics/protocol

"
Multi-bulk replies

Commands like LRANGE need to return multiple values (every element of the list is a value, and LRANGE needs to return more than a single element). This is accomplished using multiple bulk writes, prefixed by an initial line indicating how many bulk writes will follow. The first byte of a multi bulk reply is always *. Example:

C: LRANGE mylist 0 3
s: *4
s: $3
s: foo
s: $3
s: bar
s: $5
s: Hello
s: $5
s: World

As you can see the multi bulk reply is exactly the same format used in order to send commands to the Redis server using the unified protocol.

The first line the server sent is *4\r\n in order to specify that four bulk replies will follow. Then every bulk write is transmitted.

If the specified key does not exist, the key is considered to hold an empty list and the value 0 is sent as multi bulk count. Example:

C: LRANGE nokey 0 1
S: *0

When the BLPOP command times out, it returns the nil multi bulk reply. This type of multi bulk has count -1 and should be interpreted as a nil value. Example:

C: BLPOP key 1
S: *-1

A client library API SHOULD return a nil object and not an empty list when this happens. This is necessary to distinguish between an empty list and an error condition (for instance the timeout condition of the BLPOP command).
"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment