早年我写代码时候,也喜欢用#if 0来调试,现在不用了。如下代码主要是跟优化level相关: #ifndef REDIS_STATIC#define REDIS_STATIC static#endif/* Optimization levels for size-based filling.* Note that the largest possible limit is 16k, so e
第一个函数是分配新的rax, 返回的是指针。这个函数对异常的考虑也还很全,如果获取不到内存,就返回NULL /* Allocate a new rax and return its pointer. On out of memory the function* returns NULL. */rax *raxNew(void) {rax *rax = rax_malloc(sizeof(*r
这里主要讲rdb的一些check信息,不是咱们缕清逻辑的重点,不想看的话,可以跳过: struct {rio *rio;robj *key; /* Current key we are reading. */int key_type; /* Current key type if != -1. */unsigned l
触发并掩码掉给定的fd: static int aeApiLookupPending(aeApiState *state, int fd) {uint_t i;for (i = 0; i < state->npending; i++) {if (state->pending_fds[i] == fd)return (i);}return (-1);}/** Helper function to
fd_set是网络编程中很重要的结构体,rfds是读描述集, wfds是写描述集合,这是使用需要非常清晰,看最后的select, 知道怎么样了吧: #include <sys/select.h>#include <string.h>typedef struct aeApiState {fd_set rfds, wfds;/* We need to have a copy of the fd s
这里主要讲位域操作,大家要对基本的位操作有深刻的理解: /* The following set.*Bitfield and get.*Bitfield functions implement setting* and getting arbitrary size (up to 64 bits) signed and unsigned integers* at arbitrary positio
处理非阻塞的client, 整个实现还是比较简单的: /* This function is called in the beforeSleep() function of the event loop* in order to process the pending input buffer of clients that were* unblocked after a blocking op
SSL大家应该很熟悉,就是为了确保安全的,openssl应该听说过吧: /* Wrapper around redisSecureConnection to avoid hiredis_ssl dependencies if* not building with TLS support.*/int cliSecureConnection(redisContext *c, cliSSLconfi
加载配置文件中的信息,非重点: /* Load the cluster config from 'filename'.** If the file does not exist or is zero-length (this may happen because* when we lock the nodes.conf file, we create a zero-length one for