mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-17 09:17:39 +01:00
* filer.redis3: prefix every key via getKey, honoring keyPrefix Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: read username and keyPrefix options into client config Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: reject a username configured without a password go-redis only sends AUTH when a password is set, so a configured username with an empty password silently connects as the default user instead of the intended ACL user. Fail loudly at initialize instead. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: cover keyPrefix scoping in the store tests Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: derive the test prefix and kv key from the per-run directory --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
69 lines
2.1 KiB
Go
69 lines
2.1 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, &Redis3SentinelStore{})
|
|
}
|
|
|
|
type Redis3SentinelStore struct {
|
|
UniversalRedis3Store
|
|
}
|
|
|
|
func (store *Redis3SentinelStore) GetName() string {
|
|
return "redis3_sentinel"
|
|
}
|
|
|
|
func (store *Redis3SentinelStore) Initialize(configuration util.Configuration, prefix string) (err error) {
|
|
tlsConfig, err := redis_tls.Config(configuration, prefix)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return store.initialize(
|
|
configuration.GetStringSlice(prefix+"addresses"),
|
|
configuration.GetString(prefix+"masterName"),
|
|
configuration.GetString(prefix+"username"),
|
|
configuration.GetString(prefix+"password"),
|
|
configuration.GetString(prefix+"sentinel_username"),
|
|
configuration.GetString(prefix+"sentinel_password"),
|
|
configuration.GetInt(prefix+"database"),
|
|
configuration.GetString(prefix+"keyPrefix"),
|
|
tlsConfig,
|
|
redis_conf.Read(configuration, prefix),
|
|
)
|
|
}
|
|
|
|
func (store *Redis3SentinelStore) initialize(addresses []string, masterName string, username string, password string, sentinelUsername string, sentinelPassword string, database int, keyPrefix string, tlsConfig *tls.Config, settings redis_conf.Settings) (err error) {
|
|
if err := checkUserPassword(username, password); err != nil {
|
|
return err
|
|
}
|
|
if err := checkUserPassword(sentinelUsername, sentinelPassword); err != nil {
|
|
return err
|
|
}
|
|
options := &redis.FailoverOptions{
|
|
MasterName: masterName,
|
|
SentinelAddrs: addresses,
|
|
Username: username,
|
|
Password: password,
|
|
SentinelUsername: sentinelUsername,
|
|
SentinelPassword: sentinelPassword,
|
|
DB: database,
|
|
TLSConfig: tlsConfig,
|
|
}
|
|
settings.ApplyToFailover(options)
|
|
store.Client = redis.NewFailoverClient(options)
|
|
store.redsync = redsync.New(goredis.NewPool(store.Client))
|
|
store.keyPrefix = keyPrefix
|
|
return
|
|
}
|