BITOP operation destkey key [key …]

    Time complexity: O(N)

    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:

    As you can see NOT is special as it only takes an input key, because it performs inversion of bits so it only makes sense as an unary operator.

    The result of the operation is always stored at .

    The same holds true for non-existent keys, that are considered as a stream of zero bytes up to the length of the longest string.

    Integer reply

    The size of the string stored in the destination key, that is equal to the size of the longest input string.

    redis> SET key1 "foobar"

    redis> SET key2 "abcdef"

    redis> GET dest

    redis>

    is a good complement to the pattern documented in the BITCOUNT command documentation. Different bitmaps can be combined in order to obtain a target bitmap where the population counting operation is performed.

    See the article called "" for a interesting use cases.

    BITOP is a potentially slow command as it runs in O(N) time. Care should be taken when running it against long input strings.

    For real-time metrics and statistics involving large inputs a good approach is to use a replica (with read-only option disabled) where the bit-wise operations are performed to avoid blocking the master instance.