Build Your Own Redis: Introduction [0/4]
This is the introductory article in a series where we’ll build a toy Redis clone in Ruby. If you’d like to code-along, try the Build your own Redis challenge!
Next article: Barebones TCP Server
Sections in this article:
Introduction to Redis
Redis is a data store that supports supports multiple data-structures such as strings, hashes, lists, sets and more.
Redis clients talk to Redis by issuing commands over TCP, using the Redis Protocol.
Here’s an example of the redis client talking to a redis server.
➜ redis-cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET a hey
OK
127.0.0.1:6379> GET a
"hey"
What we’ll build
In this course, we’ll build a toy redis clone that’s capable of handling basic
commands like PING
, SET
and GET
. Along the way we’ll learn about event
loops (how Redis serves multiple clients using a single thread), the Redis
protocol and more.
Since our implementation will speak the Redis
Protocol, we’ll even be able to interact
with it using redis-cli
.
[1] Barebones TCP Server
We’ll spawn a TCP server that binds to a port and accepts connections from clients.
[2] PING <-> PONG
We’ll respond to the PING
command. The reply
to this command will be sent using the Redis
Protocol.
[3] Concurrent Clients
We’ll make our server more capable when it comes to handling multiple clients at the same time. We’ll do this using an event loop, like the official Redis implementation does.
This is probably the most challenging part of this entire series.
[4] ECHO
We’ll respond to the ECHO
command. In this
stage, we’ll learn to parse RESP (the Redis
Protocol).
[5] SET & GET
We’ll implement SET and GET. Our server will now be capable of handling state.
This article is still in progress.
Ready for the first lesson?