46 lines
630 B
Go
46 lines
630 B
Go
package bloomfilter
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
type Mode int
|
|
|
|
const (
|
|
ModeLocal Mode = iota
|
|
ModeRedis
|
|
)
|
|
|
|
type Options struct {
|
|
mode Mode
|
|
client *redis.Client
|
|
key string
|
|
}
|
|
|
|
type Option func(*Options)
|
|
|
|
func UseLocal() Option {
|
|
return func(o *Options) {
|
|
o.mode = ModeLocal
|
|
}
|
|
}
|
|
|
|
func UseRedis(client *redis.Client, key string) Option {
|
|
return func(o *Options) {
|
|
o.mode = ModeRedis
|
|
o.client = client
|
|
o.key = key
|
|
}
|
|
}
|
|
|
|
func (o *Options) repairOption() error {
|
|
if o.mode == ModeRedis {
|
|
if o.client == nil || o.key == "" {
|
|
return errors.New("no addr provided")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|