TOPK.RESERVE
TOPK.RESERVE key topk [width depth decay]
- Group
- Top-K
- Complexity
- O(1)
- Arity
- -1 (at least 1 words, counting the command name)
- Flags
- fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
TOPK.RESERVE creates an empty Top-K structure at key. It keeps the topk
items seen most often, with estimated counts, in a fixed amount of memory, so
you can find heavy hitters (popular products, noisy clients, trending terms)
without storing a counter per item.
The Top-K must exist before you add to it.
Arguments
Section titled “Arguments”| Argument | Effect |
|---|---|
topk |
How many items to keep, 1 to 4294967295. |
width |
Counters per row used to estimate counts (default 8). More counters give more accurate counts and take more memory. |
depth |
Number of counter rows (default 7). More rows make large errors less likely and take more memory. |
decay |
A value above 0 and at most 1 (default 0.9) that sets how readily rare items give way to frequent ones. |
width, depth and decay are given together or not at all.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Created | Simple string OK |
Simple string OK |
Error replies:
TopK: key already existsif the key exists (with any type).TopK: invalid k,TopK: invalid width,TopK: invalid depthTopK: invalid decay value. must be '<= 1' & '> 0'TopK: Insufficient memory to create the keyERR wrong number of arguments for 'topk.reserve' commandwhen only some ofwidth,depth,decayare given.
Examples
Section titled “Examples”127.0.0.1:6379> TOPK.RESERVE trending 3OK127.0.0.1:6379> TOPK.INFO trending1) k2) (integer) 33) width4) (integer) 85) depth6) (integer) 77) decay8) "0.9"127.0.0.1:6379> TOPK.RESERVE trending 5(error) TopK: key already exists127.0.0.1:6379> TOPK.RESERVE wide 10 100 5 0.9OKCompatibility
Section titled “Compatibility”Same arguments and defaults as TOPK.RESERVE in RedisBloom.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.