What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

GETBIT

Returns a bit value by offset.

Usage
GETBIT key offset
Complexity
O(1)
Since
2.2.0
ACL Categories
@bitmap, @fast, @read
Command flags
READONLY, FAST

Returns the bit value at offset in the string value stored at key.

When offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When key does not exist it is assumed to be an empty string, so offset is always out of range and the value is also assumed to be a contiguous space with 0 bits.

Examples

127.0.0.1:6379> SETBIT mykey 7 1
(integer) 0
127.0.0.1:6379> GETBIT mykey 0
(integer) 0
127.0.0.1:6379> GETBIT mykey 7
(integer) 1
127.0.0.1:6379> GETBIT mykey 100
(integer) 0

Replies

RESP2

The bit value stored at offset, one of the following:

RESP3

The bit value stored at offset, one of the following: