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#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
<offset> | Yes | No | Zero-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.
| Protocol | Reply |
|---|---|
| RESP2 | Integer: the bit at the offset, 0 or 1 |
| RESP3 | Integer: 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.