Redis Internals: File Event Handling

Events are the core of Redis server, reponsible for dealing with two important tasks: File events: receive the requests from multiple clients, process and responde to clients. Time events: server cron job. In this post, we will take a look at multiplexing event handling processing requests from clients. Clients connect to Redis server via sockets, but the server interacts with these clients only when the sockets can be read or written without blocking. ...

Apr 28, 2019 · 7 min · xgugeng

Redis Internals: Dict

Dictionary is a data structure for storing key-value pair. Each key in a dictionary is unique and has a corresponding value. Redis implements its own dictionary and use it for hash key. As a data structure in server side, dictionary must take memory into consideration. That’s the reason why resizing and rehashing are so significant. ...

Nov 15, 2018 · 9 min · xgugeng

Redis Internals: List

Redis provides a generic doubly linked list implementation, which is widely used in Redis. If a list key involves two many elements or there are many long strings in the list, Redis will apply linked list for it. Publish-subscribe, slow query, monitor also make use of linked list. Redis keeps the states of clients in linked list, and client’s output buffer use it too. This post will plough into the implementation of doubly linked list. ...

Nov 6, 2018 · 6 min · xgugeng

Redis Internals: SDS

C string is used only for literal constant in Redis. For the situation that the string can be modified, Redis provide a Simple Dynamic String(SDS). The key in Redis is actually a SDS, and if you insert a key-value with SET msg "hello world", a SDS instance will be constructed for the key. In this case, the value is also a SDS instance with the content of “hello world”. Besides string, SDS is also used for buffer which can serve the AOF module and client’s input. This post will dive into the implementation of SDS comparing with classic C string. ...

Nov 1, 2018 · 8 min · xgugeng

What Happens When Starting Redis

Redis is a great example of high-performance server. When I worked as a backend developer, my mentor recommended that I should read the code of Redis. And so I did, it’s rewarding. As the time goes by, the ideas behind Redis are still cutting-edge, so I think it’s time to retrospect the implementation of Redis. This post is a good beginning. It’s my habit to start from the entry when meeting a big project. In Redis, server.c is responsible for bootstrap, that’s what I pay close attention to in this post. ...

Oct 22, 2018 · 4 min · xgugeng

Redis Mind Map

This post includes a few mind maps for Redis ranging from quick start to implementation. ...

Nov 6, 2016 · 1 min · xgugeng