RESP3
RESP3 copied to clipboard
Additional "processing instruction" type
In a project I've been hacking on, a redis-like frontend for LMDB, I implemented and extended the Redis protocol with a few additional types.
One of these I think may interest you I'm calling a "processing instruction". It allows the client to send additional metadata along with a single command. Currently I am only using this functionality to allow the client to specify a different database for a single command (LMDB, like Redis, supports multiple databases within a single environment). So rather than having the client do:
- SELECT 0
- do some operation on db 0
- SELECT 15
- do some operation on db 15
- SELECT 0 -- reset the client state.
I can just explicitly SELECT 0 once, and when I need to run a single command against DB 15, I send (along with the command) a processing instruction that indicates the DB for that command should be db 15:
- do some operation on db 0
- (include processing instruction to use db 15) + do some operation on db 15
- do another operation on db 0
Another usage for processing commands could be to set/modify the expiration time on the key being operated on.
Would this not be possible by sending a attribute type with the request from the client? For example,
|1<CR><LF>
%1<CR><LF>
+use-database<CR><LF>
:1<CR><LF>
*3<CR><LF>
LPUSH<CR><LF>
somekey<CR><LF>
someval<CR><LF>
While Redis looks like it will only be allowing array-type requests from clients, the protocol can work in full-duplex. In this way you could put arbitrarily complex meta and state in the 'header' using attribute type data.
Yeah exactly, it would just be a question of how the server supported and interpreted such.