API Reference: Core Functions
This page details the main functions for configuring bitmapist, marking events, and managing data.
setup_redis()
Configures a named connection to a Redis instance.
Signature:
def setup_redis(name: str, host: str, port: int, **kw: Any) -> None:
Description:
Setup a redis system.
:param name:The name of the system.:param host:The host of the redis installation.:param port:The port of the redis installation.:param **kw:Any additional keyword arguments will be passed toredis.StrictRedis(e.g.,db=,password=).
Example:
setup_redis("stats_redis", "localhost", 6380, db=1)
mark_event("active", 1, system="stats_redis")
mark_event()
Marks a time-based event for a user.
Signature:
def mark_event(
event_name: str,
uuid: int,
system: str = "default",
now: Optional[datetime] = None,
track_hourly: Optional[bool] = None,
track_unique: Optional[bool] = None,
use_pipeline: bool = True,
) -> None:
Description:
Marks an event for hours, days, weeks and months.
:param event_name:The name of the event (e.g., "active").:param uuid:A unique integer ID for the user.:param system:The Redis system to use.:param now:Adatetimeobject for the event timestamp (defaults todatetime.now(tz=timezone.utc)).:param track_hourly:IfTrue, tracks the event at hourly granularity.:param track_unique:IfTrue, also marks a corresponding non-time-basedUniqueEventsflag.:param use_pipeline:IfTrue, uses a Redis pipeline for efficiency.
unmark_event()
Clears a time-based event for a user.
Signature:
def unmark_event(
event_name: str,
uuid: int,
system: str = "default",
now: Optional[datetime] = None,
track_hourly: Optional[bool] = None,
track_unique: Optional[bool] = None,
use_pipeline: bool = True,
) -> None:
Description:
This function has the same signature as mark_event but sets the bit to 0, effectively removing the user from the event set for the specified period.
mark_unique()
Marks a non-time-based unique event (flag) for a user.
Signature:
def mark_unique(event_name: str, uuid: int, system: str = "default") -> None:
Description:
Use this for storing user properties, A/B test groups, etc. It creates a single Redis key for the event name that is not tied to a date.
unmark_unique()
Clears a non-time-based unique event (flag) for a user.
Signature:
def unmark_unique(event_name: str, uuid: int, system: str = "default") -> None:
get_event_names()
Returns a list of all event names stored in Redis.
Signature:
def get_event_names(system: str = "default", prefix: str = "", batch: int = 10000) -> list[str]:
:param system:The Redis system to scan.:param prefix:An optional prefix to filter event names.:param batch:The batch size for the underlyingSCANcommand.
delete_all_events()
Deletes all bitmapist-related keys from the Redis database.
Signature:
def delete_all_events(system: str = "default") -> None:
Warning: This is a destructive operation.
delete_temporary_bitop_keys()
Deletes all temporary keys created by bitwise operations by scanning the entire keyspace.
Signature:
def delete_temporary_bitop_keys(system: str = "default") -> None:
Warning: This can be a slow operation on large databases.
delete_runtime_bitop_keys()
Deletes temporary bit operation keys that were created within the current thread. This is the recommended method for cleaning up temporary keys.
Signature:
def delete_runtime_bitop_keys() -> None: