aboutsummaryrefslogtreecommitdiffstats
path: root/src/dma/vendor/github.com/go-redis/redis/universal.go
diff options
context:
space:
mode:
authorToshiaki Takahashi <takahashi.tsc@ncos.nec.co.jp>2018-09-06 09:04:29 +0000
committerToshiaki Takahashi <takahashi.tsc@ncos.nec.co.jp>2018-09-07 06:03:01 +0000
commitd61931341176dad9ccff7c967a10d88fe54218fa (patch)
tree526457882d4abe0c38d2242d6daa311bf8ef51cf /src/dma/vendor/github.com/go-redis/redis/universal.go
parent73abc060f31a6bf866fa1dad0a1a6efdfd94d775 (diff)
src: Add DMA localagent
Change-Id: Ibcee814fbc9a904448eeb368a1a26bbb69cf54aa Signed-off-by: Toshiaki Takahashi <takahashi.tsc@ncos.nec.co.jp>
Diffstat (limited to 'src/dma/vendor/github.com/go-redis/redis/universal.go')
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/universal.go151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/dma/vendor/github.com/go-redis/redis/universal.go b/src/dma/vendor/github.com/go-redis/redis/universal.go
new file mode 100644
index 00000000..9e30c81d
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/universal.go
@@ -0,0 +1,151 @@
+package redis
+
+import (
+ "crypto/tls"
+ "time"
+)
+
+// UniversalOptions information is required by UniversalClient to establish
+// connections.
+type UniversalOptions struct {
+ // Either a single address or a seed list of host:port addresses
+ // of cluster/sentinel nodes.
+ Addrs []string
+
+ // The sentinel master name.
+ // Only failover clients.
+ MasterName string
+
+ // Database to be selected after connecting to the server.
+ // Only single-node and failover clients.
+ DB int
+
+ // Only cluster clients.
+
+ // Enables read only queries on slave nodes.
+ ReadOnly bool
+
+ MaxRedirects int
+ RouteByLatency bool
+
+ // Common options
+
+ OnConnect func(*Conn) error
+ MaxRetries int
+ Password string
+ DialTimeout time.Duration
+ ReadTimeout time.Duration
+ WriteTimeout time.Duration
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+ TLSConfig *tls.Config
+}
+
+func (o *UniversalOptions) cluster() *ClusterOptions {
+ if len(o.Addrs) == 0 {
+ o.Addrs = []string{"127.0.0.1:6379"}
+ }
+
+ return &ClusterOptions{
+ Addrs: o.Addrs,
+ MaxRedirects: o.MaxRedirects,
+ RouteByLatency: o.RouteByLatency,
+ ReadOnly: o.ReadOnly,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+func (o *UniversalOptions) failover() *FailoverOptions {
+ if len(o.Addrs) == 0 {
+ o.Addrs = []string{"127.0.0.1:26379"}
+ }
+
+ return &FailoverOptions{
+ SentinelAddrs: o.Addrs,
+ MasterName: o.MasterName,
+ DB: o.DB,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+func (o *UniversalOptions) simple() *Options {
+ addr := "127.0.0.1:6379"
+ if len(o.Addrs) > 0 {
+ addr = o.Addrs[0]
+ }
+
+ return &Options{
+ Addr: addr,
+ DB: o.DB,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+// --------------------------------------------------------------------
+
+// UniversalClient is an abstract client which - based on the provided options -
+// can connect to either clusters, or sentinel-backed failover instances or simple
+// single-instance servers. This can be useful for testing cluster-specific
+// applications locally.
+type UniversalClient interface {
+ Cmdable
+ Watch(fn func(*Tx) error, keys ...string) error
+ Process(cmd Cmder) error
+ WrapProcess(fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error)
+ Subscribe(channels ...string) *PubSub
+ PSubscribe(channels ...string) *PubSub
+ Close() error
+}
+
+var _ UniversalClient = (*Client)(nil)
+var _ UniversalClient = (*ClusterClient)(nil)
+
+// NewUniversalClient returns a new multi client. The type of client returned depends
+// on the following three conditions:
+//
+// 1. if a MasterName is passed a sentinel-backed FailoverClient will be returned
+// 2. if the number of Addrs is two or more, a ClusterClient will be returned
+// 3. otherwise, a single-node redis Client will be returned.
+func NewUniversalClient(opts *UniversalOptions) UniversalClient {
+ if opts.MasterName != "" {
+ return NewFailoverClient(opts.failover())
+ } else if len(opts.Addrs) > 1 {
+ return NewClusterClient(opts.cluster())
+ }
+ return NewClient(opts.simple())
+}