method

RedisClient.bitpos

key: KeyLike,
bit: 0 | 1,
...options: string | number[]
): Promise<number>;

Find the position of the first bit set to 1 or 0 in a string

@param key

The key to search

@param bit

The bit value to search for (0 or 1)

@param options

Optional start, end, and index unit (BYTE or BIT)

@returns

Promise that resolves with the position of the first bit, or -1 if not found

await redis.set("mykey", Buffer.from([0xff, 0xf0, 0x00]));
await redis.bitpos("mykey", 0); // 12
await redis.bitpos("mykey", 1, 2); // -1

Referenced types

type KeyLike = string | ArrayBufferView | Blob