Write A Redis Client
of your ownGao Chao
https://github.com/reterVision
What is Redis
https://github.com/antirez/redis
Key-Value Store
Event Driven
redis-server: a TCP server using client-server model.
Communication Protocol
*<param_count>
$<command_string_length>
command
$<param_string_length>
param
$<param_string_length>
param
….
Sample Communication
Client -> Server
*3
$4
HGET
$14
test:hash
$5
hello
Server -> Client
$13
[1,2,3,4,5,6]
Let’s write some code!
https://gist.github.com/reterVision/7037762
Pipeline
*3
$4
HGET
$9
test:hash
$5
hello
(continue with left…)
*2
$7
HGETALL
$9
test:hash
Essentially is cache all the commands you want to send to redis-
server
and send them all at once when you feel good.
Pipeline Response
$13
[1,2,3,4,5,6]
*2
$2
55
$13
[1,2,3,4,5,6]
<- String length of first cmd response
<- First cmd resp
<- Parameters count of second cmd resp
<- String length of 1st param of second cmd resp
<- 1st param of second cmd resp
<- String length of 2nd param of second cmd resp
<- 2nd param of second cmd resp
More Code
https://github.com/andymccurdy/redis-py
https://github.com/nrk/redis-lua
Thank you!