Upstash Documentation

GETBIT

Get the bit value at offset.
2 min read

Use GETBIT to read a single bit of the string stored at a key.

The offset is counted in bits from the start of the value, so offset 0 is the most significant bit of the first byte. When the key does not exist, or the offset lies past the end of the stored string, the bit reads as 0 rather than producing an error.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.
<offset>YesNoZero-based bit offset to read.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Integer: the bit at the offset, 0 or 1
RESP3Integer: the bit at the offset, 0 or 1
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs