You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
977 B

3 years ago
3 years ago
3 years ago
  1. package redis3
  2. import (
  3. "github.com/go-redis/redis/v8"
  4. "github.com/go-redsync/redsync/v4"
  5. "github.com/go-redsync/redsync/v4/redis/goredis/v8"
  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. }