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

feat: implement Sliding Window Bloom Filter #715

Merged
merged 1 commit into from
Jan 11, 2025
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
59 changes: 59 additions & 0 deletions rueidisprob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,62 @@ func main() {
fmt.Println(count) // 1
}
```

### Sliding Window Bloom Filter

It is a variation of the standard Bloom filter that adds a sliding window mechanism.
Useful for use cases where you need to keep track of items for a certain amount of time.

Example:

```go
package main

import (
"context"
"fmt"
"time"

"github.com/redis/rueidis"
"github.com/redis/rueidis/rueidisprob"
)

func main() {
client, err := rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"localhost:6379"},
})
if err != nil {
panic(err)
}

sbf, err := NewSlidingBloomFilter(client, "sliding_bloom_filter", 1000, 0.01, time.Minute)

err = sbf.Add(context.Background(), "hello")
if err != nil {
panic(err)
}

err = sbf.Add(context.Background(), "world")
if err != nil {
panic(err)
}

exists, err := sbf.Exists(context.Background(), "hello")
if err != nil {
panic(err)
}
fmt.Println(exists) // true

exists, err = sbf.Exists(context.Background(), "world")
if err != nil {
panic(err)
}
fmt.Println(exists) // true

count, err := sbf.Count(context.Background())
if err != nil {
panic(err)
}
fmt.Println(count) // 2
}
```
Loading
Loading