Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

1.9 KB
Raw Blame
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, &RedisCluster3Store{})
}

type RedisCluster3Store struct {
	UniversalRedis3Store
}

func (store *RedisCluster3Store) GetName() string {
	return "redis_cluster3"
}

func (store *RedisCluster3Store) Initialize(configuration util.Configuration, prefix string) (err error) {

	configuration.SetDefault(prefix+"useReadOnly", false)
	configuration.SetDefault(prefix+"routeByLatency", false)

	tlsConfig, err := redis_tls.Config(configuration, prefix)
	if err != nil {
		return err
	}

	return store.initialize(
		configuration.GetStringSlice(prefix+"addresses"),
		configuration.GetString(prefix+"username"),
		configuration.GetString(prefix+"password"),
		configuration.GetString(prefix+"keyPrefix"),
		configuration.GetBool(prefix+"useReadOnly"),
		configuration.GetBool(prefix+"routeByLatency"),
		tlsConfig,
		redis_conf.Read(configuration, prefix),
	)
}

func (store *RedisCluster3Store) initialize(addresses []string, username string, password string, keyPrefix string, readOnly, routeByLatency bool, tlsConfig *tls.Config, settings redis_conf.Settings) (err error) {
	if err := checkUserPassword(username, password); err != nil {
		return err
	}
	options := &redis.ClusterOptions{
		Addrs:          addresses,
		Username:       username,
		Password:       password,
		ReadOnly:       readOnly,
		RouteByLatency: routeByLatency,
		TLSConfig:      tlsConfig,
	}
	settings.ApplyToCluster(options)
	store.Client = redis.NewClusterClient(options)
	store.redsync = redsync.New(goredis.NewPool(store.Client))
	store.keyPrefix = keyPrefix
	return
}