Data Structures Used By Redis Internally
Posted By : Abhinav Gupta | 31-May-2018
What is Redis ?
Redis is a database written in C. It is a key-value pair based database. Redis's event-driven nature is what sets it apart from other databases. Redis makes use of to implement its asynchronous behavior.
libae
Data Structures used by Redis :
This is a brief introduction of few of the important data structures and their fields that are used by the Redis Database. This is by no means an exhaustive list of all the data structures that are used by Redis.
Redis makes use of a global struct named which is of the type for defining all the server configuration and shared states. Some of the important fields in this struct are
server
struct redisServer
struct redisServer
{
...
redisDb *db;
dict *commands;
list *clients;
client *master;
...
}
where "..." signifies that there are numerous other fields
struct redisDb
Each redisDb instance has a unique id, and many hashtables to monitor data that is relevant to the database.dict
dict.h
redisServer
adlist.h
struct client
struct cli
ent
are
struct client
{
int fd;
sds querybuf;
int argc;
robj **argv;
redisDb *db;
list *reply;
char buf[PROTO_REPLY_CHUNK_BYTES];
...
}
fd
is the client socket file descriptorargc
stands for the number of arguments given by the client for a commandargv
are the actual arguments that are given by the client. This is a pointer of the robj
robj
struct redisObject
{
unsigned type:4;
unsigned encoding:4;
unsigned lru:LRU_BITS;
int refcount;
void *ptr;
} robj;
This data structure is very general, and it is designed in such a way that it can represent all basic datatypes used in Redis like strings, lists, sets, sorted sets etc.
sds
sds.h
buf
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Abhinav Gupta
Abhinav is good at developing commercial software that save time and money. He is experienced with node.js and javascript.