BITOP to combine several strings with a bitwise operation and store the result in another key.
Source strings are combined bit by bit, and shorter ones are treated as if they were padded with zero bits up to the length of the longest input, so the destination always ends up as long as the longest source. A missing key counts as an empty string, and if the result is empty the destination key is deleted. The reply is the length of the stored value in bytes.
AND, OR, and XOR accept any number of source keys and NOT accepts exactly one. The remaining operators compare the first key with the rest: DIFF keeps the bits set in the first key and in none of the others, DIFF1 keeps the bits set in at least one of the other keys but not in the first, ANDOR keeps the bits set in the first key and in at least one of the others, and ONE keeps the bits set in exactly one of the source keys. DIFF, DIFF1, and ANDOR each require at least two source keys.
This is how bitmaps are used as sets: with one bit per user, AND gives users present in every bitmap and OR gives users present in any of them, and BITCOUNT then turns the result into a number.
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