Support redis cluster mode (#1181)

* use redisConfig of protocol instead of redisConfig and use redis of protocol to create redis client to support redis cluster mode too
This commit is contained in:
Tom Xiong
2022-11-22 10:36:43 -08:00
committed by GitHub
parent 76c65a5da7
commit e5dabd466e
3 changed files with 26 additions and 86 deletions
+17 -36
View File
@@ -14,6 +14,7 @@ import (
"gopkg.in/yaml.v3"
"github.com/livekit/protocol/logger"
redisLiveKit "github.com/livekit/protocol/redis"
)
var DefaultStunServers = []string{
@@ -33,21 +34,21 @@ const (
)
type Config struct {
Port uint32 `yaml:"port"`
BindAddresses []string `yaml:"bind_addresses"`
PrometheusPort uint32 `yaml:"prometheus_port,omitempty"`
RTC RTCConfig `yaml:"rtc,omitempty"`
Redis RedisConfig `yaml:"redis,omitempty"`
Audio AudioConfig `yaml:"audio,omitempty"`
Video VideoConfig `yaml:"video,omitempty"`
Room RoomConfig `yaml:"room,omitempty"`
TURN TURNConfig `yaml:"turn,omitempty"`
Ingress IngressConfig `yaml:"ingress,omitempty"`
WebHook WebHookConfig `yaml:"webhook,omitempty"`
NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"`
KeyFile string `yaml:"key_file,omitempty"`
Keys map[string]string `yaml:"keys,omitempty"`
Region string `yaml:"region,omitempty"`
Port uint32 `yaml:"port"`
BindAddresses []string `yaml:"bind_addresses"`
PrometheusPort uint32 `yaml:"prometheus_port,omitempty"`
RTC RTCConfig `yaml:"rtc,omitempty"`
Redis redisLiveKit.RedisConfig `yaml:"redis,omitempty"`
Audio AudioConfig `yaml:"audio,omitempty"`
Video VideoConfig `yaml:"video,omitempty"`
Room RoomConfig `yaml:"room,omitempty"`
TURN TURNConfig `yaml:"turn,omitempty"`
Ingress IngressConfig `yaml:"ingress,omitempty"`
WebHook WebHookConfig `yaml:"webhook,omitempty"`
NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"`
KeyFile string `yaml:"key_file,omitempty"`
Keys map[string]string `yaml:"keys,omitempty"`
Region string `yaml:"region,omitempty"`
// LogLevel is deprecated
LogLevel string `yaml:"log_level,omitempty"`
Logging LoggingConfig `yaml:"logging,omitempty"`
@@ -134,18 +135,6 @@ type VideoConfig struct {
DynacastPauseDelay time.Duration `yaml:"dynacast_pause_delay,omitempty"`
}
type RedisConfig struct {
Address string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
DB int `yaml:"db"`
UseTLS bool `yaml:"use_tls"`
MasterName string `yaml:"sentinel_master_name"`
SentinelUsername string `yaml:"sentinel_username"`
SentinelPassword string `yaml:"sentinel_password"`
SentinelAddresses []string `yaml:"sentinel_addresses"`
}
type RoomConfig struct {
// enable rooms to be automatically created
AutoCreate bool `yaml:"auto_create"`
@@ -241,7 +230,7 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
Video: VideoConfig{
DynacastPauseDelay: 5 * time.Second,
},
Redis: RedisConfig{},
Redis: redisLiveKit.RedisConfig{},
Room: RoomConfig{
AutoCreate: true,
EnabledCodecs: []CodecSpec{
@@ -331,14 +320,6 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
return conf, nil
}
func (conf *Config) HasRedis() bool {
return conf.Redis.Address != "" || conf.Redis.SentinelAddresses != nil
}
func (conf *Config) UseSentinel() bool {
return conf.Redis.SentinelAddresses != nil
}
func (conf *Config) IsTURNSEnabled() bool {
if conf.TURN.Enabled && conf.TURN.TLSPort != 0 {
return true