Latest web development tutorials

Redis Getbit command

Redis string (string)

Redis Getbit command string value to the stored key to get bit (bit) on the specified offset.

grammar

redis Getbit basic command syntax is as follows:

redis 127.0.0.1:6379> GETBIT KEY_NAME OFFSET

Available versions

> = 2.2.0

return value

String value of the specified bit (bit) offsets on.

When the offset OFFSET than the length of the string value is large, or key does not exist, 0 is returned.

Examples

# 对不存在的 key 或者不存在的 offset 进行 GETBIT, 返回 0

redis> EXISTS bit
(integer) 0

redis> GETBIT bit 10086
(integer) 0


# 对已存在的 offset 进行 GETBIT

redis> SETBIT bit 10086 1
(integer) 0

redis> GETBIT bit 10086
(integer) 1

Redis string (string)