加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Redis系列(三):redisServer、redisDb、redisObject、sds四大

发布时间:2020-12-16 04:38:07 所属栏目:安全 来源:网络整理
导读:一.源码下载: Windows中的Redis源码下载: https://github.com/microsoftarchive/redis/tr ee/3.2 根据官网说明可知,用VS2013编译,但是必须更新到update5,?否则会出现各种编译错误,确实如此,之前用vs2013的其它版本,出现各种错误,无法修改。 打开VS20

一.源码下载:

Windows中的Redis源码下载:https://github.com/microsoftarchive/redis/tree/3.2

根据官网说明可知,用VS2013编译,但是必须更新到update5,?否则会出现各种编译错误,确实如此,之前用vs2013的其它版本,出现各种错误,无法修改。

打开VS2013---帮助---关于,即可查看自己的VS版本,例如我重装之后的update5:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

不是VS2013 update5的可以下载重装。

vs2013 update5下载链接:http://www.121down.com/soft/softview-43319.html

打开RedisServer.sln?一共9个项目:

?

Linux中的Redis源码:http://download.redis.io/releases/redis-6.0.5.tar.gz

二.整体示意图:

?

?

?

?

?

?

三.源码解析

1.redisServer 解析

通过main函数来初始化redisServer()

int main(int argc,char **argv) {
    struct timeval tv;
    int j;
    //.....
    initServer();
}

?

?监听端口

?这里面的server代表的就是redisServer

?初始化db数目

?2.redisDb解析

typedef  redisDb {
dict *dict; /* The keyspace for this DB */
dict *expires;  Timeout of keys with a timeout set 
dict *blocking_keys;  Keys with clients waiting for data (BLPOP)
dict *ready_keys;  Blocked keys that received a PUSH 
dict *watched_keys;  WATCHED keys for MULTI/EXEC CAS */
int id;  Database ID long long avg_ttl;  Average TTL,just for stats 
unsigned long expires_cursor;  Cursor of the active expire cycle. 
list *defrag_later;  List of key names to attempt to defrag one by one,gradually. 
} redisDb;

 

?

?

3.redisObject解析

typedef  redisObject {
unsigned type:4;
unsigned encoding:;
unsigned lru:LRU_BITS;  LRU time (relative to global lru_clock) or
* LFU data (least significant 8 bits frequency
* and most significant 16 bits access time).  refcount;
void *ptr;
} robj;

编码:

?

?类型:

?

?

4.sds解析

在C语言中都是用char数组来存放数据,在Redis中为了性能,封装了char

常用的一种结构体

 __attribute__ ((__packed__)) sdshdr8 {
    uint8_t len;  used 
    uint8_t alloc;  excluding the header and null terminator 
    unsigned char flags;  3 lsb of type,5 unused bits */
    char buf[];
};

?

?

?

注:有兴趣的朋友可以通过cmake把redis编译成vs解决方案项目

?

?

?

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读