-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcluster.go
36 lines (30 loc) · 954 Bytes
/
cluster.go
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
package gorillaradix
import (
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
"github.com/mediocregopher/radix/v3"
)
// Redis Cluster specific options
type ClusterConfiguration struct {
ConnectionOptions
Hosts []string
}
func NewStoreCluster(configuration ClusterConfiguration, options SessionOptions) (sessions.Store, error) {
connectFunction := createRadixConnectionFunction(configuration.ConnectionOptions)
poolFunc := func(network, addr string) (radix.Client, error) {
return radix.NewPool(
network,
addr,
100,
radix.PoolConnFunc(connectFunction),
radix.PoolPingInterval(configuration.PingTimeout))
}
pool, err := radix.NewCluster(configuration.Hosts, radix.ClusterPoolFunc(poolFunc))
applyDefaultSessionConfiguration(&options)
return &RadixStore{
redis: pool,
Codecs: securecookie.CodecsFromPairs([]byte(options.Secret)),
Options: options,
serializer: GobSerializer{},
}, err
}