diff --git a/valkeyprob/bloomfilter.go b/valkeyprob/bloomfilter.go index 019e670..0fcd1f9 100644 --- a/valkeyprob/bloomfilter.go +++ b/valkeyprob/bloomfilter.go @@ -132,7 +132,7 @@ type BloomFilter interface { Delete(ctx context.Context) error // Count returns count of items in Bloom filter. - Count(ctx context.Context) (uint, error) + Count(ctx context.Context) (uint64, error) } type bloomFilter struct { @@ -317,7 +317,7 @@ func (c *bloomFilter) Delete(ctx context.Context) error { return resp.Error() } -func (c *bloomFilter) Count(ctx context.Context) (uint, error) { +func (c *bloomFilter) Count(ctx context.Context) (uint64, error) { resp := c.client.Do( ctx, c.client.B(). @@ -325,18 +325,14 @@ func (c *bloomFilter) Count(ctx context.Context) (uint, error) { Key(c.counter). Build(), ) - if resp.Error() != nil { - if valkey.IsValkeyNil(resp.Error()) { + count, err := resp.AsUint64() + if err != nil { + if valkey.IsValkeyNil(err) { return 0, nil } - return 0, resp.Error() - } - - count, err := resp.AsUint64() - if err != nil { return 0, err } - return uint(count), nil + return count, nil } diff --git a/valkeyprob/countingbloomfilter.go b/valkeyprob/countingbloomfilter.go index babe6f3..a6cbc72 100644 --- a/valkeyprob/countingbloomfilter.go +++ b/valkeyprob/countingbloomfilter.go @@ -144,15 +144,15 @@ type CountingBloomFilter interface { // ItemMinCount returns the minimum count of item in the Counting Bloom Filter. // If the item is not in the Counting Bloom Filter, it returns a zero value. // Minimum count is not always accurate because of the hash collisions. - ItemMinCount(ctx context.Context, key string) (uint, error) + ItemMinCount(ctx context.Context, key string) (uint64, error) // ItemMinCountMulti returns the minimum count of items in the Counting Bloom Filter. // If the item is not in the Counting Bloom Filter, it returns a zero value. // Minimum count is not always accurate because of the hash collisions. - ItemMinCountMulti(ctx context.Context, keys []string) ([]uint, error) + ItemMinCountMulti(ctx context.Context, keys []string) ([]uint64, error) // Count returns count of items in Counting Bloom Filter. - Count(ctx context.Context) (uint, error) + Count(ctx context.Context) (uint64, error) } type countingBloomFilter struct { @@ -344,7 +344,7 @@ func (f *countingBloomFilter) Delete(ctx context.Context) error { return resp.Error() } -func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uint, error) { +func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uint64, error) { counts, err := f.ItemMinCountMulti(ctx, []string{key}) if err != nil { return 0, err @@ -353,7 +353,7 @@ func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uin return counts[0], nil } -func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []string) ([]uint, error) { +func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []string) ([]uint64, error) { if len(keys) == 0 { return nil, nil } @@ -377,7 +377,7 @@ func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []stri return nil, err } - counts := make([]uint, 0, len(messages)) + counts := make([]uint64, 0, len(messages)) minCount := uint64(math.MaxUint64) for i, message := range messages { cnt, err := message.AsUint64() @@ -394,7 +394,7 @@ func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []stri } if (i+1)%int(f.hashIterations) == 0 { - counts = append(counts, uint(minCount)) + counts = append(counts, minCount) minCount = uint64(math.MaxUint64) } } @@ -402,7 +402,7 @@ func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []stri return counts, nil } -func (f *countingBloomFilter) Count(ctx context.Context) (uint, error) { +func (f *countingBloomFilter) Count(ctx context.Context) (uint64, error) { resp := f.client.Do( ctx, f.client.B(). @@ -419,5 +419,5 @@ func (f *countingBloomFilter) Count(ctx context.Context) (uint, error) { return 0, err } - return uint(count), nil + return count, nil }