字符串

redis各版本存在差异,基于redis5.0.3

1、stirng 长度<=44 encoding enbstr >=45 encoding raw

  enbstr使用连续内存

  raw 对象头和对象体不连续的内存

2、为什么是44

  1)对象头(总共占16byte)    redis所有种类的对象都需要一个对象头 

    int4 type; 类型

    int4 encoding;编码类型 如上面的enbstr和raw

    int24 lru;     记录对象的lru信息好像和内存不足后回收策略有关

    int32 refcount; 引用计数,通过refcount判断是否需要回收

    void * ptr;     8byte 64-bit系统

  2)SDS对象(3+capcity)

    int8 capcity; 数组最大长度

    int8 len;   数组使用长度

    int8 flags;     标志位

    byte[] content; capcity*1byte

  3) 44+19+1=64byte (字符串是以 \0 结尾占用一个字节)

3、redis字符串的扩容不同于rehash

    1M以内扩容内存增加一倍

    大于1M只增加1M的空间

4、redis字符串最大大小是512M

    

       

posted @ 2019-02-17 20:18  man1s  阅读(207)  评论(0编辑  收藏  举报