Redis.Commands.Cuckoo (Redis v0.8.0)

Copy Markdown View Source

Command builders for Redis Cuckoo filter (CF.*) operations.

A Cuckoo filter is a probabilistic data structure similar to a Bloom filter but with two key advantages: it supports deletion of previously added items, and it can report approximate item counts. Like Bloom filters, Cuckoo filters may return false positives but never false negatives. The trade-off is slightly higher memory usage per element compared to Bloom filters.

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 Cuckoo filter for up to 10_000 items
Redis.command(conn, Cuckoo.reserve("users", 10_000))

# Add, check, and delete an item
Redis.pipeline(conn, [
  Cuckoo.add("users", "alice"),
  Cuckoo.exists("users", "alice"),
  Cuckoo.del("users", "alice")
])

Summary

Functions

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

Deletes an item from a Cuckoo filter.

Checks whether an item may exist in a Cuckoo filter.

Functions

add(key, item)

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

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

addnx(key, item)

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

count(key, item)

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

del(key, item)

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

Deletes an item from a Cuckoo filter.

This is the main advantage over Bloom filters. Returns 1 if the item was found and deleted, 0 otherwise. Deleting an item that was not added may cause false negatives for other items.

exists(key, item)

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

Checks whether an item may exist in a Cuckoo 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()]

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

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

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

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