Files
seaweedfs/weed/filer/redis3/redis_store.go
T
Chris Lu 83f754763e filer: make the redis connection settings configurable (#10441)
The sentinel stores hardcoded a 30s read timeout and a 1m retry backoff.
After a sentinel failover every request that picked a pooled connection to
the old master sat there for 30s before the connection was retired, and the
pool timeout derived from it (read timeout + 1s) queued the rest behind
them. The other redis stores took the go-redis defaults with no way to tune
anything.

Read the dial, timeout and pool knobs from each redis store section instead,
keeping the go-redis default for every key left unset.
2026-07-25 19:55:39 -07:00

53 lines
1.3 KiB
Go

package redis3
import (
"crypto/tls"
"github.com/go-redsync/redsync/v4"
"github.com/go-redsync/redsync/v4/redis/goredis/v9"
"github.com/redis/go-redis/v9"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/filer/redis_conf"
"github.com/seaweedfs/seaweedfs/weed/filer/redis_tls"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func init() {
filer.Stores = append(filer.Stores, &Redis3Store{})
}
type Redis3Store struct {
UniversalRedis3Store
}
func (store *Redis3Store) GetName() string {
return "redis3"
}
func (store *Redis3Store) Initialize(configuration util.Configuration, prefix string) (err error) {
tlsConfig, err := redis_tls.Config(configuration, prefix)
if err != nil {
return err
}
return store.initialize(
configuration.GetString(prefix+"address"),
configuration.GetString(prefix+"password"),
configuration.GetInt(prefix+"database"),
tlsConfig,
redis_conf.Read(configuration, prefix),
)
}
func (store *Redis3Store) initialize(hostPort string, password string, database int, tlsConfig *tls.Config, settings redis_conf.Settings) (err error) {
options := &redis.Options{
Addr: hostPort,
Password: password,
DB: database,
TLSConfig: tlsConfig,
}
settings.ApplyTo(options)
store.Client = redis.NewClient(options)
store.redsync = redsync.New(goredis.NewPool(store.Client))
return
}