blob: 8c73244140036e46ccb75cf99c41a284a4ac3344 (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package broadcast
import (
"errors"
"github.com/go-redis/redis/v8"
)
// Config configures the broadcast extension.
type Config struct {
// RedisConfig configures redis broker.
Redis *RedisConfig
}
// Hydrate reads the configuration values from the source configuration.
//func (c *Config) Hydrate(cfg service.Config) error {
// if err := cfg.Unmarshal(c); err != nil {
// return err
// }
//
// if c.Redis != nil {
// return c.Redis.isValid()
// }
//
// return nil
//}
// InitDefaults enables in memory broadcast configuration.
func (c *Config) InitDefaults() error {
return nil
}
// RedisConfig configures redis broker.
type RedisConfig struct {
// Addr of the redis server.
Addr string
// Password to redis server.
Password string
// DB index.
DB int
}
// clusterOptions
func (cfg *RedisConfig) redisClient() redis.UniversalClient {
return redis.NewClient(&redis.Options{
Addr: cfg.Addr,
Password: cfg.Password,
PoolSize: 2,
})
}
// check if redis config is valid.
func (cfg *RedisConfig) isValid() error {
if cfg.Addr == "" {
return errors.New("redis addr is required")
}
return nil
}
|