mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 17:36:29 +01:00
add clusters support for sessiondb:redis:Radix() #1339
Former-commit-id: d748d1e19a29851abbbfc0264fd04c462158b645
This commit is contained in:
parent
07046ab978
commit
2cd217f110
|
@ -24,8 +24,14 @@ const (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Network protocol. Defaults to "tcp".
|
// Network protocol. Defaults to "tcp".
|
||||||
Network string
|
Network string
|
||||||
// Addr of the redis server. Defaults to "127.0.0.1:6379".
|
// Addr of a single redis server instance.
|
||||||
|
// See "Clusters" field for clusters support.
|
||||||
|
// Defaults to "127.0.0.1:6379".
|
||||||
Addr string
|
Addr string
|
||||||
|
// Clusters a list of network addresses for clusters.
|
||||||
|
// If not empty "Addr" is ignored.
|
||||||
|
// Currently only Radix() Driver supports it.
|
||||||
|
Clusters []string
|
||||||
// Password string .If no password then no 'AUTH'. Defaults to "".
|
// Password string .If no password then no 'AUTH'. Defaults to "".
|
||||||
Password string
|
Password string
|
||||||
// If Database is empty "" then no 'SELECT'. Defaults to "".
|
// If Database is empty "" then no 'SELECT'. Defaults to "".
|
||||||
|
|
|
@ -2,6 +2,7 @@ package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/mediocregopher/radix/v3"
|
"github.com/mediocregopher/radix/v3"
|
||||||
|
@ -39,7 +40,6 @@ func (r *RadixDriver) Connect(c Config) error {
|
||||||
c.Delim = DefaultDelim
|
c.Delim = DefaultDelim
|
||||||
}
|
}
|
||||||
|
|
||||||
customConnFunc := func(network, addr string) (radix.Conn, error) {
|
|
||||||
var options []radix.DialOpt
|
var options []radix.DialOpt
|
||||||
|
|
||||||
if c.Password != "" {
|
if c.Password != "" {
|
||||||
|
@ -61,10 +61,28 @@ func (r *RadixDriver) Connect(c Config) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return radix.Dial(network, addr, options...)
|
var connFunc radix.ConnFunc
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
pool, err := radix.NewPool(c.Network, c.Addr, c.MaxActive, radix.PoolConnFunc(customConnFunc))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user