Skip to content

Commit 175a3bb

Browse files
authored
Merge pull request #4 from wangthomas/modify_add
change add - return true if the key is already added
2 parents a7891f5 + 8aa1253 commit 175a3bb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

client/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
type Client interface {
1515
Create(ctx context.Context, filter string) error
16-
Add(ctx context.Context, filter string, hashes []uint64) error
16+
Add(ctx context.Context, filter string, hashes []uint64) (bool, error)
1717
Has(ctx context.Context, filter string, hashes []uint64) (bool, error)
1818
Drop(ctx context.Context, filter string) error
1919
Shutdown()
@@ -52,16 +52,20 @@ func (t *bloomClient) Create(ctx context.Context, filter string) error {
5252
}
5353

5454
// Add issues a command to add a specified key to a given filter
55-
func (t *bloomClient) Add(ctx context.Context, filter string, hashes []uint64) error {
55+
func (t *bloomClient) Add(ctx context.Context, filter string, hashes []uint64) (bool, error) {
5656
req := &pb.KeyRequest{
5757
FilterName: filter,
5858
Hashes: hashes,
5959
}
6060

6161
timedCtx, cancel := context.WithTimeout(ctx, t.timeout)
6262
defer cancel()
63-
_, err := t.client.Add(timedCtx, req)
64-
return err
63+
resp, err := t.client.Add(timedCtx, req)
64+
var has bool
65+
if resp != nil {
66+
has = resp.Has
67+
}
68+
return has, err
6569
}
6670

6771
// Has checks if a given key exists in a specified filter

0 commit comments

Comments
 (0)