Write a redis client of your own
-
Upload
chao-gao -
Category
Technology
-
view
726 -
download
1
Transcript of Write a redis client of your own
![Page 1: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/1.jpg)
Write A Redis Client
of your ownGao Chao
https://github.com/reterVision
![Page 2: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/2.jpg)
What is Redis
https://github.com/antirez/redis
Key-Value Store
Event Driven
redis-server: a TCP server using client-server model.
![Page 3: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/3.jpg)
Communication Protocol
*<param_count>
$<command_string_length>
command
$<param_string_length>
param
$<param_string_length>
param
….
![Page 4: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/4.jpg)
Sample Communication
Client -> Server
*3
$4
HGET
$14
test:hash
$5
hello
Server -> Client
$13
[1,2,3,4,5,6]
![Page 5: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/5.jpg)
Let’s write some code!
https://gist.github.com/reterVision/7037762
![Page 6: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/6.jpg)
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.
![Page 7: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/7.jpg)
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
![Page 8: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/8.jpg)
More Code
https://github.com/andymccurdy/redis-py
https://github.com/nrk/redis-lua
![Page 9: Write a redis client of your own](https://reader036.fdocuments.us/reader036/viewer/2022071814/55a67ef61a28ab6c6f8b47bc/html5/thumbnails/9.jpg)
Thank you!