Skip to main content

TOPK.ADD

Syntax

TOPK.ADD key item [item ...]

Time complexity: O(n * depth) where n is the number of items

ACL categories: @topk

Adds one or more items to the Top-K data structure stored at key. The key must already exist (created via TOPK.RESERVE); otherwise, an error is returned. If an added item displaces an existing item from the top-k list, the displaced item is returned.

Return

Array reply: An array with one entry per item. Each entry is either:

  • A bulk string with the name of the item that was displaced from the top-k list.
  • nil if no item was displaced.

Examples

dragonfly> TOPK.RESERVE topk 2
OK

dragonfly> TOPK.ADD topk foo bar baz
1) (nil)
2) (nil)
3) foo

dragonfly> TOPK.LIST topk
1) baz
2) bar

See also

TOPK.RESERVE | TOPK.INCRBY | TOPK.QUERY | TOPK.LIST