Redis Source Analysis (34)---The implementation analysis of REDIS.H service end (1)

Source: Internet
Author: User
Tags compact error code object object redis server


The last time just analyzed the client structure analysis, thinking more simple, clear, and finally learning is the implementation of the service end, the service in Redis but the heavy, which basically contains the previous modules involved in all the points of knowledge, from the Redis of the head file can be seen, Redis.h The amount of code has been broken 1000+ line, and are just a few variables, macro-defined declarations, and some method prototype declarations. So, today's summary is the same as yesterday, first do not do the specific implementation of learning, first from the overall perspective of the service side of the overall design ideas, this document from the beginning of the statement just can learn.


/* ----------------------- Declare the required header files, mainly for the operation files of various structures ------- ------------- */
#include "ae.h" /* Event driven programming library Event-driven library*/
#include "sds.h" /* Dynamic safe strings Dynamic String Library */
#include "dict.h" /* Hash tables Hash Dictionary */
#include "adlist.h" /* Linked lists Ordinary doubly linked list */
#include "zmalloc.h" /* total memory usage aware version of malloc/free Memory Application Management Library */
#include "anet.h" /* Networking the easy way Network Operations Library */
#include "ziplist.h" /* Compact list data structure Compressed list */
#include "intset.h" /* Compact integer set structure Shaping set structure */
#include "version.h" /* Version macro version number file*/
#include "util.h" /* Misc functions useful in many places The same method class */
#include "latency.h" /* Latency monitor API Delay Monitoring Method */
#include "sparkline.h" /* ASII graphs API Microline Gallery */

/* ----------------------------- Depending on the module, macros define different variables -------- -------- */
/* 1.Error codes Redis error code*/
/* 2.Static server configuration server some static variable values */
/* 3.Protocol and I/O related defines the definition of protocols and I/O related variables*/
/* 4.Hash table parameters Hash table parameters * /
/* 5.Command flags The flag definition for command line operations */
/* 6.Object types Object type, including List, String, Hash, etc. */
/* 7.Objects encoding Object encoding type */
/* 8.Defines related to the dump file format RDB save format, 14-bit, 32-bit, etc. */
/* 9. Status of AOF states AOF files*/
/* 10.Client flags client flag flag */
/* 11.Client request types Client request type, INLINE and MULTIBULK*/
/* 12.Client classes for client limits Client type */
/* 13.Slave replication state replication status*/
/* 14.List related stuff List position, head or tail*/
/* 15.Sort operations Sort operation type, ascending or descending, etc. */
/* 16.Log levels Log level*/
/* 17.Anti-warning macro... Warning message*/
/* 18.Append only defines append only variable */
/* 19.Zip structure related defaults ziplist compressed list variable */
/* 20.HyperLogLog defines HLLC variable definition */
/* 21.Sets operations codes Set the opcode for the operation*/
/* 22.Redis maxmemory strategies Redis memory operation strategy */
/* 23.Scripting */
/* 24.Units time units, subtle and milliseconds*/
/* 25.SHUTDOWN flags */
/* 26.Command call flags, see call() function */
/* 27.Command propagation flags, see propagate() function */
/* 28.Keyspace changes notification classes. Notification type*/

/*------------------------------------------------ -----------------------------
 * Data types related definitions of data types
 *------------------------------------------------- ---------------------------*/
1.typedef struct redisObject /* Redis Object object */
2.typedef struct redisDb
3.typedef struct multiCmd
4.typedef struct multiState
5.typedef struct blockingState
6.typedef struct readyList
7.typedef struct redisClient /* Redis client structure */
8.struct saveparam
9.struct sharedObjectsStruct
10.typedef struct zskiplistNode
11.typedef struct zskiplist
12.typedef struct zset
13.typedef struct clientBufferLimitsConfig
14.typedef struct redisOp
15.typedef struct redisOpArray
16.struct redisServer /* Redis server-side structure definition */
17.struct redisCommand / * Redis server command command structure definition * /

/*------------------------------------------------ -----------------------------
 * Functions prototypes method prototype
 *------------------------------------------------- ---------------------------*/
/* 1.Utils general class method */
/* 2.networking.c -- Networking and Client related operations Network Operations Method */
/* 3.List data type List operation method */
/* 4.MULTI/EXEC/WATCH... Command execution method*/
/* 5.Redis object implementation Redis Object object method */
/* 6.Synchronous I/O with timeout I/O synchronization class method*/
/* 7.Replication master-slave replication method */
/* 8.Generic persistence functions Some methods of persistence loading */
/* 9.AOF persistence AOF log file persistence method */
/* 10.Core functions Core class methods*/
/* 11.Sorted sets data type Sort set method */
/* 12.Set data type set type data operation method */
/* 13.Hash data type Hash type method operation method */
/* 14.Pub / Sub publish subscription method */
/* 15.Keyspace events notification ketSpace event notification method */
/* 16.Configuration configuration class method */
/* 17.db.c -- Keyspace access API db related methods */
/* 18.Sentinel */
/* 19.Scripting */
/* 20.Git SHA1 */
/* 21.Commands prototypes command prototype method */




Main 4 Large modules




1. Reference header File Declaration



2. Macro definition variable definition



3. Statement of data structure body



4. Method Prototype Declaration



In particular, it is proposed here that the REDISOBJECT,REDISCLIENT,REDISSERVER structure definitions that appear everywhere in the code are defined in this file.





/* The actual redis Object */
#define REDIS_LRU_BITS
#define REDIS_LRU_CLOCK_MAX (1<<redis_lru_bits)- 1)/* Max value of OBJ->LRU * *
#define REDIS_LRU_CLOCK_RESOLUTION 1/LRU CLOCK resolution in seconds * * Typed
EF struct Redisobject {
    unsigned type:4;
    unsigned encoding:4;
    unsigned lru:redis_lru_bits; /* LRU time (relative to Server.lruclock) */
    int refcount;
    void *ptr;
} RobJ;
Redisclient,redisserver's structure definition is very similar, which contains a bunch of attributes, a long row down.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.