Redis_code_reading

Redis code reading: sds

Last weekend, I read and summarized zmalloc.c which provides basic memory allocation mechanisms of Redis. In this weekend, I explored sds.c which implements many functions to manage a dynamic string efficiently; in fact, “sds” stands for Simple Dynamic String. This post describes a core of sds implementations. The version of Redis is 3.0.5. I put some comments on following code snippets. sds is just a char pointer with hidden header As well as zmalloc family, sds implicitly keeps track of available size and length of string by placing them on its (hidden) prefix.

Redis code reading: zmalloc

This post explains some fundamental functions of memory allocation used in Redis. These functions are kind of wrapper to hide architecture-dependent implementations and to keep track of the size of total allocated memory. The version of Redis is 3.0.5. Available Backend Implementations A backend memory allocator of zmalloc can be one of the following: libc malloc Default except Linux. jemmaloc http://www.canonware.com/jemalloc/ It seems less fragmentation than libc malloc.

Visualize rough Redis source code dependencies

Now, I’m getting interested in Redis. The concept of Redis seems to be different from other general purpose database like relational, document, graph databases; each of these employs a one-size-fits-all data model. By no free lunch theorem, these databases cannot store and fetch some kind of data efficiently. Some of this data can be efficiently handled by Redis since it provides specialized and primitive data structures. This specialty attracts me.