Skip to main content
Use SETBIT to set a single bit of the string stored at a key to 0 or 1. The offset is counted in bits from the start of the value and the reply is the bit’s previous value. If the key does not exist, or the offset lies past the end of the current value, the string is first extended with zero bits, so writing to a large offset allocates every byte up to it. Keep offsets dense, for example by mapping each user to a small sequential id. Bitmaps built this way are read back with GETBIT, counted with BITCOUNT, and combined with BITOP.

Syntax

Arguments

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.
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.