API Reference: Bit Operation Classes
These classes provide an explicit way to perform bitwise operations on event sets. They are an alternative to using Python's bitwise operators (&, |, ^, ~).
Each operation creates a new temporary key in Redis to store the result. The result object itself behaves like any other event object, supporting len(), in, iteration, and further bitwise operations.
BitOpAnd
Performs a bitwise AND (intersection) on two or more event sets.
Constructor:
BitOpAnd(system_or_event, *events)
Description:
The result contains only the user IDs present in all of the provided event sets.
Example:
from bitmapist import DayEvents, BitOpAnd
# Users who were active AND completed a task today
result = BitOpAnd(DayEvents('active'), DayEvents('task:completed'))
BitOpOr
Performs a bitwise OR (union) on two or more event sets.
Constructor:
BitOpOr(system_or_event, *events)
Description:
The result contains user IDs present in any of the provided event sets.
Example:
from bitmapist import DayEvents, BitOpOr
# Users who were active OR completed a task today
result = BitOpOr(DayEvents('active'), DayEvents('task:completed'))
BitOpXor
Performs a bitwise XOR (exclusive OR) on two or more event sets.
Constructor:
BitOpXor(system_or_event, *events)
Description:
The result contains user IDs present in an odd number of the provided event sets. For two sets, this means users present in one set but not both.
Example:
from bitmapist import DayEvents, BitOpXor
# Users who were active but did NOT complete a task,
# plus users who completed a task but were NOT active.
result = BitOpXor(DayEvents('active'), DayEvents('task:completed'))
BitOpNot
Performs a bitwise NOT (inversion) on a single event set.
Constructor:
BitOpNot(system_or_event, *events)
Description:
The result contains all user IDs not present in the provided event set. Note that the concept of "all users" is relative to the highest bit set across your entire Redis database.
Example:
from bitmapist import DayEvents, BitOpNot
# All users who were NOT active today
not_active = BitOpNot(DayEvents('active'))