user1059595
user1059595

Reputation: 13

Redis command line syntax

Can someone please explain how the following Redis command gives me back the content? What do the individual numbered lines are responsible for?

1: *3
2: $4
3: hget
4: $21
5: zc:k:b23_cache_config
6: $1
7: d
8: $5264$5264

Upvotes: 0

Views: 1782

Answers (1)

j.w.r
j.w.r

Reputation: 4249

The message format is called the unified request protocol.

An asterisk * denotes how many arguments are to be expected in this request. So, *3 is for three arguments.

A dollar sign $ denotes how many bytes are to be expected in the argument. So, $1 is for one byte.

*<number of arguments> CR LF
$<number of bytes of argument 1> CR LF
<argument data> CR LF
...
$<number of bytes of argument N> CR LF
<argument data> CR LF

The raw message from your example would look like:

*3\r\n$4\r\nhget\r\n$21\r\nzc:k:b23_cache_config\r\n$1\r\nd\r\n

This particular request will return a bulk reply response, which looks like:

$<number of bytes> CR LF
<DATA> CR LF

If the requested key doesn't exist then the reply will be:

$-1

Upvotes: 5

Related Questions