Skip to content

Commit e4010f9

Browse files
DEV: add attribute type to the RESP3 spec. (#722)
* DEV: add attribute type to the RESP3 spec. * Update protocol-spec.md * Apply suggestions from code review Thank you, @andy-stark-redis! Co-authored-by: andy-stark-redis <[email protected]> --------- Co-authored-by: andy-stark-redis <[email protected]>
1 parent 609c72a commit e4010f9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

content/develop/reference/protocol-spec.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ The following table summarizes the RESP data types that Redis supports:
131131
| [Bulk errors](#bulk-errors) | RESP3 | Aggregate | `!` |
132132
| [Verbatim strings](#verbatim-strings) | RESP3 | Aggregate | `=` |
133133
| [Maps](#maps) | RESP3 | Aggregate | `%` |
134+
| [Attributes](#attributes) | RESP3 | Aggregate | `|` |
134135
| [Sets](#sets) | RESP3 | Aggregate | `~` |
135136
| [Pushes](#pushes) | RESP3 | Aggregate | `>` |
136137

@@ -530,6 +531,54 @@ The first element is a key, followed by the corresponding value, then the next k
530531
`key1, value1, key2, value2, ...`.
531532
{{% /alert %}}
532533

534+
<a name="attribute-reply"></a>
535+
536+
### Attributes
537+
538+
The attribute type is exactly like the Map type, but instead of a `%` character as the first byte, the `|` character is used. Attributes describe a dictionary exactly like the Map type. However the client should not consider such a dictionary part of the reply, but as auxiliary data that augments the reply.
539+
540+
For example, newer versions of Redis may include the ability to report the popularity of keys for every executed command. The reply to the command `MGET a b` may be the following:
541+
542+
|1<CR><LF>
543+
+key-popularity<CR><LF>
544+
%2<CR><LF>
545+
$1<CR><LF>
546+
a<CR><LF>
547+
,0.1923<CR><LF>
548+
$1<CR><LF>
549+
b<CR><LF>
550+
,0.0012<CR><LF>
551+
*2<CR><LF>
552+
:2039123<CR><LF>
553+
:9543892<CR><LF>
554+
555+
The actual reply to `MGET` is just the two item array `[2039123, 9543892]`. The returned attributes specify the popularity, or frequency of requests, given as floating point numbers ranging from `0.0` to `1.0`, of the keys mentioned in the original command. Note: the actual implementation in Redis may differ.
556+
557+
When a client reads a reply and encounters an attribute type, it should read the attribute, and continue reading the reply. The attribute reply should be accumulated separately, and the user should have a way to access such attributes. For instance, if we imagine a session in an higher level language, something like this could happen:
558+
559+
```python
560+
> r = Redis.new
561+
#<Redis client>
562+
> r.mget("a","b")
563+
#<Redis reply>
564+
> r
565+
[2039123,9543892]
566+
> r.attribs
567+
{:key-popularity => {:a => 0.1923, :b => 0.0012}}
568+
```
569+
570+
Attributes can appear anywhere before a valid part of the protocol identifying a given type, and supply information only about the part of the reply that immediately follows. For example:
571+
572+
*3<CR><LF>
573+
:1<CR><LF>
574+
:2<CR><LF>
575+
|1<CR><LF>
576+
+ttl
577+
:3600
578+
:3<CR><LF>
579+
580+
In the above example the third element of the array has associated auxiliary information of `{ttl:3600}`. Note that it's not up to the client library to interpret the attributes, but it should pass them to the caller in a sensible way.
581+
533582
<a name="set-reply"></a>
534583

535584
### Sets

0 commit comments

Comments
 (0)