TOPK.ADD
TOPK.ADD key item [item ...]
- Group
- Top-K
- Complexity
- O(n * depth), n being the items
- Arity
- -1 (at least 1 words, counting the command name)
- Flags
- none
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
TOPK.ADD counts one sighting of each item in the Top-K at key, in
order. When the list is full and an item outside it reaches the count of the
least frequent listed item, it takes that item’s place, and the reply tells
you which item left.
The Top-K must exist (see TOPK.RESERVE). To count several sightings at once, use TOPK.INCRBY.
Return value
Section titled “Return value”An array with one element per item, the same shape in RESP2 and RESP3:
| Element | Value |
|---|---|
| An item left the list | Bulk string: the item that left |
| Nothing left the list | Nil (RESP3: null) |
Error replies: TopK: key does not exist, and WRONGTYPE if the key holds
another type.
Examples
Section titled “Examples”127.0.0.1:6379> TOPK.RESERVE trending 2 50 4 0.9OK127.0.0.1:6379> TOPK.ADD trending redis hotkv hotkv1) (nil)2) (nil)3) (nil)127.0.0.1:6379> TOPK.ADD trending valkey valkey1) "redis"2) (nil)127.0.0.1:6379> TOPK.LIST trending1) "hotkv"2) "valkey"Compatibility
Section titled “Compatibility”Same as TOPK.ADD in RedisBloom.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.