@@ -2,6 +2,7 @@ package redis_bloom_go
22
33import (
44 "errors"
5+ "fmt"
56 "github.com/gomodule/redigo/redis"
67 "strconv"
78 "strings"
@@ -174,3 +175,32 @@ func (client *Client) TopkList(key string) ([]string, error) {
174175 result , err := conn .Do ("TOPK.LIST" , key )
175176 return redis .Strings (result , err )
176177}
178+
179+ // Returns number of required items (k), width, depth and decay values.
180+ func (client * Client ) TopkInfo (key string ) (map [string ]string , error ) {
181+ conn := client .Pool .Get ()
182+ defer conn .Close ()
183+ reply , err := conn .Do ("TOPK.INFO" , key )
184+ values , err := redis .Values (reply , err )
185+ if err != nil {
186+ return nil , err
187+ }
188+ if len (values )% 2 != 0 {
189+ return nil , errors .New ("expects even number of values result" )
190+ }
191+
192+ m := make (map [string ]string , len (values )/ 2 )
193+ for i := 0 ; i < len (values ); i += 2 {
194+ k := values [i ].(string )
195+ switch v := values [i + 1 ].(type ) {
196+ case []byte :
197+ m [k ] = string (values [i + 1 ].([]byte ))
198+ break
199+ case int64 :
200+ m [k ] = strconv .FormatInt (values [i + 1 ].(int64 ), 10 )
201+ default :
202+ return nil , fmt .Errorf ("unexpected element type for (Ints,String), got type %T" , v )
203+ }
204+ }
205+ return m , err
206+ }
0 commit comments