Skip to content

Commit 4607523

Browse files
committed
Add withcount option
1 parent d99b299 commit 4607523

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ func (client *Client) TopkQuery(key string, items []string) ([]int64, error) {
276276
}
277277

278278
// Return full list of items in Top K list.
279+
func (client *Client) TopkListWithCount(key string) (map[string]int64, error) {
280+
conn := client.Pool.Get()
281+
defer conn.Close()
282+
return ParseInfoReply(redis.Values(conn.Do("TOPK.LIST", key, "WITHCOUNT")))
283+
}
284+
279285
func (client *Client) TopkList(key string) ([]string, error) {
280286
conn := client.Pool.Get()
281287
defer conn.Close()

client_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ func TestClient_TopkQuery(t *testing.T) {
228228
assert.Nil(t, err)
229229
assert.Equal(t, 3, len(keys))
230230
assert.Equal(t, []string{"A", "B", "E"}, keys)
231+
232+
// WithCount option
233+
keysWithCount, err := client.TopkListWithCount(key1)
234+
assert.Nil(t, err)
235+
assert.Equal(t, 3, len(keysWithCount))
236+
assert.Equal(t, map[string]int64{"A": 4, "B": 3, "E": 3}, keysWithCount)
231237
}
232238

233239
func TestClient_TopkInfo(t *testing.T) {

0 commit comments

Comments
 (0)