redis_store.go 820 B

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