-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
35 lines (30 loc) · 900 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package redis
import "go.uber.org/zap"
// An Option can be passed to the Memory function for opt-in functionality.
type Option func(*Config) error
// WithConfig is an Option to have full control over all redis connection options.
func WithConfig(newConf Config) Option {
return func(oldConf *Config) error {
oldConf.Addr = newConf.Addr
oldConf.Key = newConf.Key
oldConf.Password = newConf.Password
oldConf.DB = newConf.DB
oldConf.Logger = newConf.Logger
return nil
}
}
// WithLogger is an Option to let the Redis memory use a specific logger.
func WithLogger(logger *zap.Logger) Option {
return func(conf *Config) error {
conf.Logger = logger
return nil
}
}
// WithKey is an Option to use a different redis key to store the memories of
// the bot (default is "joe-bot").
func WithKey(key string) Option {
return func(conf *Config) error {
conf.Key = key
return nil
}
}