BITOP

Since 1.1.0Bitmaps

Syntax

BITOP <AND | OR | XOR | NOT> destkey key [key ...]
  • Flags: write
  • ACL categories: @bitmap, @slow, @write
  • Arity: -4

Combines the strings at the source keys bit by bit and stores the result at destkey. Shorter strings count as padded with zero bytes. A missing key is an empty string.

Operations

OperationEach result bit is set when
ANDit is set in every key
ORit is set in any key
XORit is set in an odd number of keys
NOTit is not set in the one key given
DIFFit is set in the first key and in none of the others
DIFF1it is not set in the first key, but is set in at least one of the others
ANDORit is set in the first key and in at least one of the others
ONEit is set in exactly one key

NOT takes exactly one source key; DIFF, DIFF1 and ANDOR take at least two. DIFF, DIFF1, ANDOR and ONE are the operations Redis 8.2 added.

Reply

  • The length of the string stored at destkey, in bytes.

Examples

> SET k1 foof
OK
> SET k2 kook
OK
> BITOP AND d k1 k2
(integer) 4
> GET d
"boob"
> BITOP OR d k1 k2
(integer) 4
> GET d
"oooo"
> BITOP NOT d k1 k2
(error) ERR BITOP NOT must be called with a single source key