Skip to content

Commit a57f3d2

Browse files
committed
更新 redis.c 注释中关于清理字典的代码
1 parent eb09547 commit a57f3d2

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/redis.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,28 +637,32 @@ dictType migrateCacheDictType = {
637637
};
638638

639639
/*
640-
* 检查字典节点的使用率是否低于系统允许的最小比率
640+
* 检查字典的使用率是否低于系统允许的最小比率
641641
*
642642
* 是的话返回 1 ,否则返回 0 。
643643
*/
644644
int htNeedsResize(dict *dict) {
645645
long long size, used;
646646

647-
// 已用节点数
647+
// 哈希表已用节点数量
648648
size = dictSlots(dict);
649-
// 可用节点数
649+
650+
// 哈希表大小
650651
used = dictSize(dict);
651652

652-
// 哈希表大小大于 DICT_HT_INITIAL_SIZE
653-
// 并且空间的占用百分比为 10%
654-
// 返回真
653+
// 当哈希表的大小大于 DICT_HT_INITIAL_SIZE
654+
// 并且字典的填充率低于 REDIS_HT_MINFILL
655+
// 返回 1
655656
return (size && used && size > DICT_HT_INITIAL_SIZE &&
656657
(used*100/size < REDIS_HT_MINFILL));
657658
}
658659

659660
/* If the percentage of used slots in the HT reaches REDIS_HT_MINFILL
660661
* we resize the hash table to save memory */
661662
/*
663+
* 对服务器中的所有数据库键空间字典、以及过期时间字典进行检查,
664+
* 看是否需要对这些字典进行收缩。
665+
*
662666
* 如果字典的使用空间比率低于 REDIS_HT_MINFILL
663667
* 那么将字典的大小缩小,让 USED/BUCKETS 的比率 <= 1
664668
*/
@@ -667,11 +671,11 @@ void tryResizeHashTables(void) {
667671

668672
for (j = 0; j < server.dbnum; j++) {
669673

670-
// 缩小 key space
674+
// 缩小键空间字典
671675
if (htNeedsResize(server.db[j].dict))
672676
dictResize(server.db[j].dict);
673677

674-
// 缩小 expire space
678+
// 缩小过期时间字典
675679
if (htNeedsResize(server.db[j].expires))
676680
dictResize(server.db[j].expires);
677681
}

0 commit comments

Comments
 (0)