@@ -2,9 +2,9 @@ package redis_bloom_go
22
33import (
44 "errors"
5- "strings"
6- "strconv"
75 "github.com/gomodule/redigo/redis"
6+ "strconv"
7+ "strings"
88)
99
1010// TODO: refactor this hard limit and revise client locking
@@ -35,7 +35,6 @@ func NewClient(addr, name string, authPass *string) *Client {
3535 return ret
3636}
3737
38-
3938// NewClientFromPool creates a new Client with the given pool and client name
4039func NewClientFromPool (pool * redis.Pool , name string ) * Client {
4140 ret := & Client {
@@ -45,50 +44,49 @@ func NewClientFromPool(pool *redis.Pool, name string) *Client {
4544 return ret
4645}
4746
48- // Reserve - Creates an empty Bloom Filter with a given desired error ratio and initial capacity.
47+ // Reserve - Creates an empty Bloom Filter with a given desired error ratio and initial capacity.
4948// args:
5049// key - the name of the filter
5150// error_rate - the desired probability for false positives
52- // capacity - the number of entries you intend to add to the filter
51+ // capacity - the number of entries you intend to add to the filter
5352func (client * Client ) Reserve (key string , error_rate float64 , capacity uint64 ) (err error ) {
5453 conn := client .Pool .Get ()
5554 defer conn .Close ()
56- _ , err = conn .Do ("BF.RESERVE" , key , strconv .FormatFloat (error_rate , 'g' , 16 , 64 ), capacity )
55+ _ , err = conn .Do ("BF.RESERVE" , key , strconv .FormatFloat (error_rate , 'g' , 16 , 64 ), capacity )
5756 return err
5857}
5958
60-
6159// Add - Add (or create and add) a new value to the filter
6260// args:
63- // key - the name of the filter
64- // item - the item to add
61+ // key - the name of the filter
62+ // item - the item to add
6563func (client * Client ) Add (key string , item string ) (exists bool , err error ) {
6664 conn := client .Pool .Get ()
6765 defer conn .Close ()
6866 return redis .Bool (conn .Do ("BF.ADD" , key , item ))
6967}
7068
71- // Exists - Determines whether an item may exist in the Bloom Filter or not.
69+ // Exists - Determines whether an item may exist in the Bloom Filter or not.
7270// args:
73- // key - the name of the filter
74- // item - the item to check for
71+ // key - the name of the filter
72+ // item - the item to check for
7573func (client * Client ) Exists (key string , item string ) (exists bool , err error ) {
7674 conn := client .Pool .Get ()
7775 defer conn .Close ()
7876 return redis .Bool (conn .Do ("BF.EXISTS" , key , item ))
7977}
8078
81- // Info - Return information about key
79+ // Info - Return information about key
8280// args:
83- // key - the name of the filter
81+ // key - the name of the filter
8482func (client * Client ) Info (key string ) (info map [string ]int64 , err error ) {
8583 conn := client .Pool .Get ()
8684 defer conn .Close ()
8785 result , err := conn .Do ("BF.INFO" , key )
8886 if err != nil {
8987 return nil , err
9088 }
91-
89+
9290 values , err := redis .Values (result , nil )
9391 if err != nil {
9492 return nil , err
@@ -98,7 +96,7 @@ func (client *Client) Info(key string) (info map[string]int64, err error) {
9896 }
9997 info = map [string ]int64 {}
10098 for i := 0 ; i < len (values ); i += 2 {
101- key , err = redis .String (values [i ], nil )
99+ key , err = redis .String (values [i ], nil )
102100 if err != nil {
103101 return nil , err
104102 }
@@ -107,5 +105,5 @@ func (client *Client) Info(key string) (info map[string]int64, err error) {
107105 return nil , err
108106 }
109107 }
110- return info , nil
108+ return info , nil
111109}
0 commit comments