Easy Tutorial
❮ Lists Brpop Keys Randomkey ❯

Redis Getbit Command

Redis Strings

The Redis Getbit command is used to get the bit at the specified offset of the string value stored at key.

Syntax

The basic syntax of the redis Getbit command is as follows:

redis 127.0.0.1:6379> GETBIT KEY_NAME OFFSET

Available Versions

= 2.2.0

Return Value

The bit at the specified offset of the string value.

Returns 0 when the offset is larger than the length of the string value or if the key does not exist.

Examples

# GETBIT on a non-existent key or non-existent offset returns 0

redis> EXISTS bit
(integer) 0

redis> GETBIT bit 10086
(integer) 0

# GETBIT on an existing offset

redis> SETBIT bit 10086 1
(integer) 0

redis> GETBIT bit 10086
(integer) 1

Redis Strings

❮ Lists Brpop Keys Randomkey ❯