3.5.1 数据结构模型

“big” 字符串的 ASCII 码: 98, 105, 103

image.png

  • Bitmaps 本身不是一种数据结构, 实际上它就是字符串

image.png

  • Bitmaps 单独提供了一套命令, 所以在 Redis 中使用 Bitmaps 和使用字符串的方法不太相同。可以把 Bitmaps想象成一个以位为单位的数组, 数组的每个单元只能存储0和1, 数组的下标在 Bitmaps 中叫做偏移量。

3.5.2 命令

1. 设置值

  • setbit

image.png

image.png

2. 获取值

  • gitbit

3. 获取 Bitmaps 指定范围值为1的个数

  • bitcount

4. Bitmaps 间的运算

  • bitop
    • and
    • or
    • not
    • xor

5. 计算 Bitmaps 中第一个值为 targetBit 的偏移量

  • bitpos

3.5.3 Bitmaps 分析

image.png

image.png

image.png