Top-K
The Top-K data structure is used to keep track of items with the highest rank, such as the top players in a leaderboard. The ranking, or score, is often based on the count of how many times an item appears in the data source (such as a stream), making the data structure ideal for identifying elements with the highest frequency. Among the most common use cases of this data structure are leaderboards, trending entities in a system, detecting network anomalies, and DDoS attacks. Here, the Top-K data structure can help answer questions such as “Which top addresses or IPs have the highest surge in the flow of requests?”
Let’s dive into an example of using the Top-K data structure and insert a few items into it. First, we must initialize it using the following command:
TOPK.RESERVE key topk [width depth decay]
In addition to key, which specifies the Top-K name, topk indicates the number of top items we want to keep track of, and width indicates the number...