BITOP
Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.
The command supports four bitwise operations: AND, OR, XOR and NOT, thus the valid forms to call the command are:
BITOP AND destkey srckey1 srckey2 srckey3 ... srckeyN
BITOP OR destkey srckey1 srckey2 srckey3 ... srckeyN
BITOP XOR destkey srckey1 srckey2 srckey3 ... srckeyN
BITOP NOT destkey srckey
The result of the operation is always stored at .
Handling of strings with different lengths
When an operation is performed between strings having different lengths, all the strings shorter than the longest string in the set are treated as if they were zero-padded up to the length of the longest string.
: the size of the string stored in the destination key, which is equal to the size of the longest input string.
Examples
dragonfly> SET key1 "foobar"
dragonfly> SET key2 "abcdef"
"OK"
(integer) 6
dragonfly> GET dest
BITOP
is a good complement to the pattern documented in the command documentation. Different bitmaps can be combined in order to obtain a target bitmap where the population counting operation is performed.
Performance considerations
For real-time metrics and statistics involving large inputs a good approach is to use a replica (with replica-read-only option enabled) where the bit-wise operations are performed to avoid blocking the master instance.