1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 04:51:56 +00:00
Former-commit-id: be901767a8008556e3499da60f6ca65f80219346
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-06-27 13:53:16 +03:00
parent b8218df789
commit 9863611264
3 changed files with 50 additions and 233 deletions

View File

@@ -10,6 +10,12 @@ import (
"github.com/mediocregopher/radix/v3/resp/resp2"
)
// radixPool an interface to complete both *radix.Pool and *radix.Cluster.
type radixPool interface {
Do(a radix.Action) error
Close() error
}
// RadixDriver the Redis service based on the radix go client,
// contains the config and the redis pool.
type RadixDriver struct {
@@ -17,7 +23,7 @@ type RadixDriver struct {
Connected bool
// Config the read-only redis database config.
Config Config
pool *radix.Pool
pool radixPool
}
// Connect connects to the redis, called only once
@@ -68,12 +74,52 @@ func (r *RadixDriver) Connect(c Config) error {
}
var connFunc radix.ConnFunc
/* Note(@kataras): according to #1545 the below does NOT work, and we should
use the Cluster instance itself to fire requests.
We need a separate `radix.Cluster` instance to do the calls,
fortunally both Pool and Cluster implement the same Do and Close methods we need,
so a new `radixPool` interface to remove any dupl code is used instead.
if len(c.Clusters) > 0 {
cluster, err := radix.NewCluster(c.Clusters)
if err != nil {
// maybe an
// ERR This instance has cluster support disabled
return err
}
connFunc = func(network, addr string) (radix.Conn, error) {
topo := cluster.Topo()
node := topo[rand.Intn(len(topo))]
return radix.Dial(c.Network, node.Addr, options...)
}
} else {
*/
connFunc = func(network, addr string) (radix.Conn, error) {
return radix.Dial(c.Network, c.Addr, options...)
}
pool, err := radix.NewPool(c.Network, c.Addr, c.MaxActive, radix.PoolConnFunc(connFunc))
if err != nil {
return err
var pool radixPool
if len(c.Clusters) > 0 {
poolFunc := func(network, addr string) (radix.Client, error) {
return radix.NewPool(network, addr, c.MaxActive, radix.PoolConnFunc(connFunc))
}
cluster, err := radix.NewCluster(c.Clusters, radix.ClusterPoolFunc(poolFunc))
if err != nil {
return err
}
pool = cluster
} else {
p, err := radix.NewPool(c.Network, c.Addr, c.MaxActive, radix.PoolConnFunc(connFunc))
if err != nil {
return err
}
pool = p
}
r.Connected = true