Command builders for Redis Top-K (TOPK.*) operations.
Top-K is a probabilistic data structure that tracks the K most frequent items (heavy hitters) in a stream of data. It uses a Count-Min Sketch internally to approximate item frequencies, making it very memory-efficient for finding popular items in high-volume streams without 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
# Track the top 3 most popular pages
Redis.command(conn, TopK.reserve("popular_pages", 3))
# Record page views and retrieve the current top-K list
Redis.pipeline(conn, [
TopK.add("popular_pages", ["/home", "/about", "/home", "/pricing"]),
TopK.list("popular_pages", withcount: true)
])
Summary
Functions
Adds one or more items to the Top-K structure.
Returns the current Top-K list. Pass withcount: true to include counts.
Checks whether one or more items are currently in the Top-K list.
Functions
Adds one or more items to the Top-K structure.
Returns a list where each element is either nil (if no item was evicted)
or the name of the item that was evicted to make room.
Returns the current Top-K list. Pass withcount: true to include counts.
Checks whether one or more items are currently in the Top-K list.
@spec reserve(String.t(), non_neg_integer(), keyword()) :: [String.t()]