GETBIT

GETBIT key offset

key 所储存的字符串值,获取指定偏移量上的位(bit)。

offset 比字符串值的长度大,或者 key 不存在时,返回 0

可用版本:

>= 2.2.0

时间复杂度:

O(1)

返回值:

字符串值指定偏移量上的位(bit)。

  1. # 对不存在的 key 或者不存在的 offset 进行 GETBIT, 返回 0
  2. redis> EXISTS bit
  3. (integer) 0
  4. redis> GETBIT bit 10086
  5. (integer) 0
  6. # 对已存在的 offset 进行 GETBIT
  7. redis> SETBIT bit 10086 1
  8. (integer) 0
  9. redis> GETBIT bit 10086
  10. (integer) 1

原文: https://wizardforcel.gitbooks.io/redis-doc/content/ref/38.html