查看Key的内部编码

object encoding key

String的三种编码

  1. int
  2. embstr
  3. raw

int

存储长整型,且长度不能超过2^64-1

emstr

存储字符串。内存是连续的,有长度限制(39/44个字节,不同版本有差异),且是只读。

raw

存储字符串。内存是非连续的,长度超出限制时使用。需要注意的是,如果使用append追加key的value,不论其是否int或者embstr的长度是否超出限制,编码会变成raw。

String经典应用场景

  1. 缓存
  2. 用户会话
  3. 计数器(increment decrement)

参考:
object.c 中,长度限制(版本:3.2)

/* Create a string object with EMBSTR encoding if it is smaller than
 * REIDS_ENCODING_EMBSTR_SIZE_LIMIT, otherwise the RAW encoding is
 * used.
 *
 * The current limit of 39 is chosen so that the biggest string object
 * we allocate as EMBSTR will still fit into the 64 byte arena of jemalloc. */
#define OBJ_ENCODING_EMBSTR_SIZE_LIMIT 44
robj *createStringObject(const char *ptr, size_t len) {
    if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT)
        return createEmbeddedStringObject(ptr,len);
    else
        return createRawStringObject(ptr,len);
}



Redis内部存储原理大纲

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-09-10
  • 2022-01-05
  • 2021-05-24
  • 2021-12-27
  • 2022-01-05
猜你喜欢
  • 2021-10-14
  • 2021-04-22
  • 2021-11-21
  • 2022-12-23
  • 2021-10-06
  • 2021-05-29
  • 2021-08-28
相关资源
相似解决方案