Documentation
¶
Overview ¶
Package bloom provides a Bloom filter implementation using Redis for storage.
A Bloom filter is a space-efficient probabilistic data structure that can tell you if an element is definitely not in a set or possibly in a set.
Features ¶
- Redis-backed storage for distributed use
- Configurable expected items and false positive rate
- Add, Exists, and Reset operations
- Multiple independent filters
Usage ¶
bf := bloom.New(redisClient, "my-filter", 10000, 0.01) bf.Add(ctx, "item") exists := bf.Exists(ctx, "item")
Index ¶
- type Filter
- func (f *Filter) Add(ctx context.Context, item string) error
- func (f *Filter) AddMany(ctx context.Context, items []string) error
- func (f *Filter) Count(ctx context.Context) (uint64, error)
- func (f *Filter) Exists(ctx context.Context, item string) (bool, error)
- func (f *Filter) ExistsMany(ctx context.Context, items []string) (map[string]bool, error)
- func (f *Filter) Reset(ctx context.Context) error
- func (f *Filter) Stats(ctx context.Context) (Stats, error)
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter represents a Bloom filter
func New ¶
New creates a new Bloom filter
expectedItems: number of items expected to be added falsePositive: desired false positive rate (0.0 to 1.0)
Example:
bf := bloom.New(client, "users", 100000, 0.01)
func (*Filter) Exists ¶
Exists checks if an item might be in the filter
Returns true if the item possibly exists, false if definitely not
Click to show internal directories.
Click to hide internal directories.