aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/redis3/redis_store.go
blob: 2eec3d37ad274dd0a4707ecaf555d2ec0e023ad8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package redis3

import (
	"github.com/chrislusf/seaweedfs/weed/filer"
	"github.com/chrislusf/seaweedfs/weed/util"
	"github.com/go-redis/redis/v8"
	"github.com/go-redsync/redsync/v4"
	"github.com/go-redsync/redsync/v4/redis/goredis/v8"
)

func init() {
	filer.Stores = append(filer.Stores, &Redis3Store{})
}

type Redis3Store struct {
	UniversalRedis3Store
}

func (store *Redis3Store) GetName() string {
	return "redis3"
}

func (store *Redis3Store) Initialize(configuration util.Configuration, prefix string) (err error) {
	return store.initialize(
		configuration.GetString(prefix+"address"),
		configuration.GetString(prefix+"password"),
		configuration.GetInt(prefix+"database"),
	)
}

func (store *Redis3Store) initialize(hostPort string, password string, database int) (err error) {
	store.Client = redis.NewClient(&redis.Options{
		Addr:     hostPort,
		Password: password,
		DB:       database,
	})
	store.redsync = redsync.New(goredis.NewPool(store.Client))
	return
}