Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyName = errors.New("name cannot be empty") ErrFalsePositiveRateLessThanEqualZero = errors.New("false positive rate cannot be less than or equal to zero") ErrFalsePositiveRateGreaterThanOne = errors.New("false positive rate cannot be greater than 1") ErrBitsSizeZero = errors.New("bits size cannot be zero") ErrBitsSizeTooLarge = errors.New("bits size is too large") )
var ( ErrEmptyCountingBloomFilterName = errors.New("name cannot be empty") ErrCountingBloomFilterFalsePositiveRateLessThanEqualZero = errors.New("false positive rate cannot be less than or equal to zero") ErrCountingBloomFilterFalsePositiveRateGreaterThanOne = errors.New("false positive rate cannot be greater than 1") ErrCountingBloomFilterBitsSizeZero = errors.New("bits size cannot be zero") )
var (
ErrWindowSizeLessThanOneSecond = errors.New("window size cannot be less than 1 second")
)
Functions ¶
This section is empty.
Types ¶
type BloomFilter ¶
type BloomFilter interface {
// Add adds an item to the Bloom filter.
Add(ctx context.Context, key string) error
// AddMulti adds one or more items to the Bloom filter.
// NOTE: If keys are too many, it can block the Redis server for a long time.
AddMulti(ctx context.Context, keys []string) error
// Exists checks if an item is in the Bloom filter.
Exists(ctx context.Context, key string) (bool, error)
// ExistsMulti checks if one or more items are in the Bloom filter.
// Returns a slice of bool values where each bool indicates whether the corresponding key was found.
ExistsMulti(ctx context.Context, keys []string) ([]bool, error)
// Reset resets the Bloom filter.
Reset(ctx context.Context) error
// Delete deletes the Bloom filter.
Delete(ctx context.Context) error
// Count returns count of items in Bloom filter.
Count(ctx context.Context) (uint64, error)
}
BloomFilter based on Redis Bitmaps. BloomFilter uses a 128-bit murmur3 hash function.
func NewBloomFilter ¶
func NewBloomFilter( client rueidis.Client, name string, expectedNumberOfItems uint, falsePositiveRate float64, opts ...BloomFilterOptionFunc, ) (BloomFilter, error)
NewBloomFilter creates a new Bloom filter. NOTE: 'name:c' is used as a counter-key in the Redis to keep track of the number of items in the Bloom filter for Count method.
func NewSlidingBloomFilter ¶ added in v1.0.53
func NewSlidingBloomFilter( redisClient rueidis.Client, name string, expectedNumberOfItems uint, falsePositiveRate float64, windowSize time.Duration, opts ...SlidingBloomFilterOptionFunc, ) (BloomFilter, error)
NewSlidingBloomFilter creates a new sliding window Bloom filter. NOTE: 'name:c' is used as a counter-key in the Redis 'name:n' is used as a next filter key in the Redis 'name:nc' is used as a next counter key in the Redis 'name:lr' is used as a last rotation key in the Redis to keep track of the items in the window.
type BloomFilterOptionFunc ¶ added in v1.0.44
type BloomFilterOptionFunc func(*BloomFilterOptions)
BloomFilterOptionFunc is used to configure BloomFilter.
func WithEnableReadOperation ¶ added in v1.0.44
func WithEnableReadOperation(enableReadOperations bool) BloomFilterOptionFunc
WithEnableReadOperation enables read operation. If enabled, Exists and ExistsMulti methods will be available as read-only operations. NOTE: If enabled, minimum redis version should be 7.0.0.
type BloomFilterOptions ¶ added in v1.0.44
type BloomFilterOptions struct {
// contains filtered or unexported fields
}
BloomFilterOptions is used to configure BloomFilter.
type CountingBloomFilter ¶ added in v1.0.34
type CountingBloomFilter interface {
// Add adds an item to the Counting Bloom Filter.
Add(ctx context.Context, key string) error
// AddMulti adds one or more items to the Counting Bloom Filter.
// NOTE: If keys are too many, it can block the Redis server for a long time.
AddMulti(ctx context.Context, keys []string) error
// Exists checks if an item is in the Counting Bloom Filter.
Exists(ctx context.Context, key string) (bool, error)
// ExistsMulti checks if one or more items are in the Counting Bloom Filter.
// Returns a slice of bool values where each bool indicates
// whether the corresponding key was found.
ExistsMulti(ctx context.Context, keys []string) ([]bool, error)
// Remove removes an item from the Counting Bloom Filter.
Remove(ctx context.Context, key string) error
// RemoveMulti removes one or more items from the Counting Bloom Filter.
// NOTE: If keys are too many, it can block the Redis server for a long time.
RemoveMulti(ctx context.Context, keys []string) error
// Delete deletes the Counting Bloom Filter.
Delete(ctx context.Context) error
// 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.
// A minimum count is not always accurate because of the hash collisions.
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.
// A minimum count is not always accurate because of the hash collisions.
ItemMinCountMulti(ctx context.Context, keys []string) ([]uint64, error)
// Count returns count of items in Counting Bloom Filter.
Count(ctx context.Context) (uint64, error)
}
CountingBloomFilter based on Hashes. CountingBloomFilter uses a 128-bit murmur3 hash function.
func NewCountingBloomFilter ¶ added in v1.0.34
func NewCountingBloomFilter( client rueidis.Client, name string, expectedNumberOfItems uint, falsePositiveRate float64, ) (CountingBloomFilter, error)
NewCountingBloomFilter creates a new Counting Bloom Filter. NOTE: 'name:cbf:c' is used as a counter-key in the Redis and 'name:cbf' is used as a filter key in the Redis to keep track of the number of items in the Counting Bloom Filter for Count method.
type SlidingBloomFilterOptionFunc ¶ added in v1.0.53
type SlidingBloomFilterOptionFunc func(o *SlidingBloomFilterOptions)
func WithReadOnlyExists ¶ added in v1.0.53
func WithReadOnlyExists(enableReadOperations bool) SlidingBloomFilterOptionFunc
type SlidingBloomFilterOptions ¶ added in v1.0.53
type SlidingBloomFilterOptions struct {
// contains filtered or unexported fields
}