Redis.Commands.Bloom (Redis v0.8.0)

Copy Markdown View Source

Command builders for Redis Bloom filter (BF.*) operations.

A Bloom filter is a space-efficient probabilistic data structure used for set membership testing. It can tell you with certainty that an item is not in the set, but positive membership responses may be false positives. The trade-off is dramatic memory savings compared to storing every element.

All functions in this module are pure and return a command list (a list of strings) suitable for passing to Redis.command/2 or Redis.pipeline/2.

Examples

# Reserve a filter allowing 0.01 (1%) error rate for up to 1000 items
Redis.command(conn, Bloom.reserve("emails", 0.01, 1000))

# Add an item and check membership
Redis.pipeline(conn, [
  Bloom.add("emails", "alice@example.com"),
  Bloom.exists("emails", "alice@example.com")
])

Summary

Functions

Adds an item to a Bloom filter, creating the filter if it does not exist.

Checks whether an item may exist in a Bloom filter.

Creates an empty Bloom filter with the given error_rate and capacity.

Functions

add(key, item)

@spec add(String.t(), String.t()) :: [String.t()]

Adds an item to a Bloom filter, creating the filter if it does not exist.

Returns 1 if the item was newly added, 0 if it may have existed already.

exists(key, item)

@spec exists(String.t(), String.t()) :: [String.t()]

Checks whether an item may exist in a Bloom filter.

Returns 1 if the item may exist (possible false positive), 0 if the item definitely does not exist.

info(key)

@spec info(String.t()) :: [String.t()]

insert(key, items, opts \\ [])

@spec insert(String.t(), [String.t()], keyword()) :: [String.t()]

loadchunk(key, iterator, data)

@spec loadchunk(String.t(), non_neg_integer(), String.t()) :: [String.t()]

madd(key, items)

@spec madd(String.t(), [String.t()]) :: [String.t()]

mexists(key, items)

@spec mexists(String.t(), [String.t()]) :: [String.t()]

reserve(key, error_rate, capacity, opts \\ [])

@spec reserve(String.t(), float(), non_neg_integer(), keyword()) :: [String.t()]

Creates an empty Bloom filter with the given error_rate and capacity.

The error rate is the desired probability of false positives (e.g. 0.01 for 1%). The capacity is the expected number of unique items. Optional keyword arguments: :expansion (growth factor) and :nonscaling (disable scaling).

scandump(key, iterator)

@spec scandump(String.t(), non_neg_integer()) :: [String.t()]