BITPOS to find the position of the first bit set to 0 or 1 in a string.
The whole value is searched unless <start> and <end> are given, and those are byte offsets by default or bit offsets when BIT is given. Both ends are inclusive and may be negative to count backwards from the end of the value. The reply is always an absolute bit position counted from the start of the string, or -1 when no matching bit is found.
One edge case is worth remembering: when you look for a 0 in a string of all ones and give no explicit end, the reply is the position of the first bit past the end of the string, because the value is treated as if it were followed by an infinite run of zero bits. Bounding the search with an explicit range returns -1 in the same situation.
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 TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs