增加注释

This commit is contained in:
LingZhaoHui 2020-10-20 21:39:01 +08:00
parent 1e023868d8
commit b4fd3e24a4
4 changed files with 29 additions and 18 deletions

View File

@ -288,6 +288,11 @@ int dictAdd(dict *d, void *key, void *val) /*调用前会查找key存在与否
* with the existing entry if existing is not NULL.
*
* If key was added, the hash entry is returned to be manipulated by the caller.
*
*
*
* dictEntry结构返回给用户
*
*/
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
{
@ -302,10 +307,11 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
if ((index = _dictKeyIndex(d, key, dictHashKey(d,key), existing)) == -1)
return NULL;
/* Allocate the memory and store the new entry.
* Insert the element in top, with the assumption that in a database
* system it is more likely that recently added entries are accessed
* more frequently. */
/*
*
* 访
*
* */
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
entry = zmalloc(sizeof(*entry));
entry->next = ht->table[index];

View File

@ -1646,6 +1646,7 @@ int processMultibulkBuffer(client *c) {
/* Setup argv array on client structure */
if (c->argv) zfree(c->argv);
// 申请argv对象所用的空间
c->argv = zmalloc(sizeof(robj*)*c->multibulklen);
}
@ -1853,6 +1854,7 @@ void processInputBuffer(client *c) {
break;
}
} else if (c->reqtype == PROTO_REQ_MULTIBULK) {
// 解析客户端信息
if (processMultibulkBuffer(c) != C_OK) break;
} else {
serverPanic("Unknown request type");

View File

@ -447,12 +447,12 @@ typedef long long ustime_t; /* microsecond time type. */
/* A redis object, that is a type able to hold a string / list / set */
/* The actual Redis Object */
#define OBJ_STRING 0 /* String object. */
#define OBJ_LIST 1 /* List object. */
#define OBJ_SET 2 /* Set object. */
#define OBJ_ZSET 3 /* Sorted set object. */
#define OBJ_HASH 4 /* Hash object. */
/* The actual Redis Object ,占用四字节*/
#define OBJ_STRING 0 /* String 对象类型 */
#define OBJ_LIST 1 /* List 对象类型. */
#define OBJ_SET 2 /* Set 对象类型. */
#define OBJ_ZSET 3 /* Sorted set 对象类型. */
#define OBJ_HASH 4 /* Hash 独享类型. */
/* The "module" object type is a special one that signals that the object
* is one directly managed by a Redis module. In this case the value points
@ -465,8 +465,8 @@ typedef long long ustime_t; /* microsecond time type. */
* by a 64 bit module type ID, which has a 54 bits module-specific signature
* in order to dispatch the loading to the right module, plus a 10 bits
* encoding version. */
#define OBJ_MODULE 5 /* Module object. */
#define OBJ_STREAM 6 /* Stream object. */
#define OBJ_MODULE 5 /* Module 对象类型. */
#define OBJ_STREAM 6 /* Stream 对象类型. */
/* Extract encver / signature from a module type ID. */
#define REDISMODULE_TYPE_ENCVER_BITS 10
@ -604,13 +604,16 @@ typedef struct RedisModuleDigest {
#define OBJ_STATIC_REFCOUNT (INT_MAX-1) /* Object allocated in the stack. */
#define OBJ_FIRST_SPECIAL_REFCOUNT OBJ_STATIC_REFCOUNT
typedef struct redisObject {
unsigned type:4;
unsigned encoding:4;
unsigned type:4; /** type表示Redis对象的类型占用4位包含 OBJ_STRING等。 */
unsigned encoding:4; /** encoding表示对象内部存储的编码在一定条件下对象的编码可以在多个编码之间转化长度占用4位,包含OBJ_ENCODING_RAW等 */
/** lru占用24位当用于LRU时表示最后一次访问时间
* LFU时16访8访0255
* 8100访object命令 */
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). */
int refcount;
void *ptr;
int refcount; /** refcount表示对象被引用的计数类型为整型实际应用中参考意义不大 */
void *ptr; /** ptr是指向具体数据的指针比如一个字符串对象该指针指向存放数据sds的地址 */
} robj;
/* The a string name for an object's type as listed above

View File

@ -99,7 +99,7 @@ void setCommand(client *c) {
robj *expire = NULL;
int unit = UNIT_SECONDS;
int flags = OBJ_SET_NO_FLAGS;
// 解析set命令的val值
for (j = 3; j < c->argc; j++) {
char *a = c->argv[j]->ptr;
robj *next = (j == c->argc-1) ? NULL : c->argv[j+1];
@ -141,7 +141,7 @@ void setCommand(client *c) {
return;
}
}
// 编码val值用于节省空间
c->argv[2] = tryObjectEncoding(c->argv[2]);
setGenericCommand(c,flags,c->argv[1],c->argv[2],expire,unit,NULL,NULL);
}