redis_store.go 977 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package redis3
  2. import (
  3. "github.com/redis/go-redis/v9"
  4. "github.com/go-redsync/redsync/v4"
  5. "github.com/go-redsync/redsync/v4/redis/goredis/v9"
  6. "github.com/seaweedfs/seaweedfs/weed/filer"
  7. "github.com/seaweedfs/seaweedfs/weed/util"
  8. )
  9. func init() {
  10. filer.Stores = append(filer.Stores, &Redis3Store{})
  11. }
  12. type Redis3Store struct {
  13. UniversalRedis3Store
  14. }
  15. func (store *Redis3Store) GetName() string {
  16. return "redis3"
  17. }
  18. func (store *Redis3Store) Initialize(configuration util.Configuration, prefix string) (err error) {
  19. return store.initialize(
  20. configuration.GetString(prefix+"address"),
  21. configuration.GetString(prefix+"password"),
  22. configuration.GetInt(prefix+"database"),
  23. )
  24. }
  25. func (store *Redis3Store) initialize(hostPort string, password string, database int) (err error) {
  26. store.Client = redis.NewClient(&redis.Options{
  27. Addr: hostPort,
  28. Password: password,
  29. DB: database,
  30. })
  31. store.redsync = redsync.New(goredis.NewPool(store.Client))
  32. return
  33. }