添加注释

This commit is contained in:
LingZhaoHui 2020-10-26 23:25:41 +08:00
parent b4fd3e24a4
commit f22dbb2dda
4 changed files with 25 additions and 14 deletions

BIN
core Normal file

Binary file not shown.

View File

@ -465,7 +465,11 @@ robj *tryObjectEncoding(robj *o) {
/* This object is encodable as a long. Try to use a shared object. /* This object is encodable as a long. Try to use a shared object.
* Note that we avoid using shared integers when maxmemory is used * Note that we avoid using shared integers when maxmemory is used
* because every object needs to have a private LRU field for the LRU * because every object needs to have a private LRU field for the LRU
* algorithm to work well. */ * algorithm to work well.
*
* 20value转换long类型
*
* */
if ((server.maxmemory == 0 || if ((server.maxmemory == 0 ||
!(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS)) && !(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS)) &&
value >= 0 && value >= 0 &&
@ -490,7 +494,9 @@ robj *tryObjectEncoding(robj *o) {
/* If the string is small and is still RAW encoded, /* If the string is small and is still RAW encoded,
* try the EMBSTR encoding which is more efficient. * try the EMBSTR encoding which is more efficient.
* In this representation the object and the SDS string are allocated * In this representation the object and the SDS string are allocated
* in the same chunk of memory to save space and cache misses. */ * in the same chunk of memory to save space and cache misses.
* 44
* */
if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT) { if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT) {
robj *emb; robj *emb;
@ -508,7 +514,9 @@ robj *tryObjectEncoding(robj *o) {
* *
* We do that only for relatively large strings as this branch * We do that only for relatively large strings as this branch
* is only entered if the length of the string is greater than * is only entered if the length of the string is greater than
* OBJ_ENCODING_EMBSTR_SIZE_LIMIT. */ * OBJ_ENCODING_EMBSTR_SIZE_LIMIT.
*
* */
trimStringObjectIfNeeded(o); trimStringObjectIfNeeded(o);
/* Return the original object. */ /* Return the original object. */

View File

@ -645,15 +645,15 @@ typedef struct clientReplyBlock {
* by integers from 0 (the default database) up to the max configured * by integers from 0 (the default database) up to the max configured
* database. The database number is the 'id' field in the structure. */ * database. The database number is the 'id' field in the structure. */
typedef struct redisDb { typedef struct redisDb {
dict *dict; /* The keyspace for this DB */ dict *dict; /* 键空间字典,存放所有键值对。 */
dict *expires; /* Timeout of keys with a timeout set */ dict *expires; /* key的超时时间字典,存放键的过期时间注意dict和expires中的键都指向同一个键的sds。 */
dict *blocking_keys; /* Keys with clients waiting for data (BLPOP)*/ dict *blocking_keys; /* 阻塞的key:处于阻塞状态的键和对应的client。*/
dict *ready_keys; /* Blocked keys that received a PUSH */ dict *ready_keys; /* 准备好的key:解除阻塞状态的键和对应的client与blocking_keys属性相对为了实现需要阻塞的命令设计 */
dict *watched_keys; /* WATCHED keys for MULTI/EXEC CAS */ dict *watched_keys; /* 执行事务的key:watch的键和对应的client主要用于事务。 */
int id; /* Database ID */ int id; /* 数据库ID */
long long avg_ttl; /* Average TTL, just for stats */ long long avg_ttl; /* 数据库内所有键的平均生存时间,用于统计 */
unsigned long expires_cursor; /* Cursor of the active expire cycle. */ unsigned long expires_cursor; /* 活动过期周期的光标。 */
list *defrag_later; /* List of key names to attempt to defrag one by one, gradually. */ list *defrag_later; /* 逐渐尝试逐个碎片整理的key列表 */
} redisDb; } redisDb;
/* Client MULTI/EXEC state */ /* Client MULTI/EXEC state */
@ -1786,6 +1786,7 @@ int collateStringObjects(robj *a, robj *b);
int equalStringObjects(robj *a, robj *b); int equalStringObjects(robj *a, robj *b);
unsigned long long estimateObjectIdleTime(robj *o); unsigned long long estimateObjectIdleTime(robj *o);
void trimStringObjectIfNeeded(robj *o); void trimStringObjectIfNeeded(robj *o);
// 判断只有对string和raw类型进行优化
#define sdsEncodedObject(objptr) (objptr->encoding == OBJ_ENCODING_RAW || objptr->encoding == OBJ_ENCODING_EMBSTR) #define sdsEncodedObject(objptr) (objptr->encoding == OBJ_ENCODING_RAW || objptr->encoding == OBJ_ENCODING_EMBSTR)
/* Synchronous I/O with timeout */ /* Synchronous I/O with timeout */

View File

@ -96,10 +96,12 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire,
/* SET key value [NX] [XX] [KEEPTTL] [EX <seconds>] [PX <milliseconds>] */ /* SET key value [NX] [XX] [KEEPTTL] [EX <seconds>] [PX <milliseconds>] */
void setCommand(client *c) { void setCommand(client *c) {
int j; int j;
robj *expire = NULL; robj *expire = NULL; // 超时时间robj类型
// 字符串的超时时间单位有秒和毫秒两种程序中根据此值来确认超时的单位此值只有两个取值分别为UNIT_SECONDSUNIT_MILLISECONDS
int unit = UNIT_SECONDS; int unit = UNIT_SECONDS;
// int类型它是一个二进制串程序中根据此值来确定key是否应该被设置到数据库。
int flags = OBJ_SET_NO_FLAGS; int flags = OBJ_SET_NO_FLAGS;
// 解析set命令的val // 解析set命令的NX、XX、EX、PX的
for (j = 3; j < c->argc; j++) { for (j = 3; j < c->argc; j++) {
char *a = c->argv[j]->ptr; char *a = c->argv[j]->ptr;
robj *next = (j == c->argc-1) ? NULL : c->argv[j+1]; robj *next = (j == c->argc-1) ? NULL : c->argv[j+1];