Redis 用intset 或hashtable 存储set。如果元素都是整数类型,就用inset 存储。
如果不是整数类型,就用hashtable(数组+链表的存来储结构)。
问题:KV 怎么存储set 的元素?key 就是元素的值,value 为null。
如果元素个数超过512 个,也会用hashtable 存储。
配置文件redis.conf
set-max-intset-entries 512
127.0.0.1:6379> sadd iset 1 2 3 4 5 6
(integer) 6
127.0.0.1:6379> object encoding iset
"intset"
127.0.0.1:6379> sadd myset a b c d e f
(integer) 6
127.0.0.1:6379> object encoding myset
"hashtable"