Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect conversion #541

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions rueidisprob/bloomfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -317,26 +317,22 @@ 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().
Get().
Key(c.counter).
Build(),
)
if resp.Error() != nil {
if rueidis.IsRedisNil(resp.Error()) {
count, err := resp.AsUint64()
if err != nil {
if rueidis.IsRedisNil(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
}
18 changes: 9 additions & 9 deletions rueidisprob/countingbloomfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,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 {
Expand Down Expand Up @@ -343,7 +343,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
Expand All @@ -352,7 +352,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
}
Expand All @@ -376,7 +376,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()
Expand All @@ -393,15 +393,15 @@ 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)
}
}

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().
Expand All @@ -418,5 +418,5 @@ func (f *countingBloomFilter) Count(ctx context.Context) (uint, error) {
return 0, err
}

return uint(count), nil
return count, nil
}