1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-07 08:55:57 +00:00

add cluster driver

Former-commit-id: 1ca87c78690a3c7a5bb40d8d669de4371bd3932c
This commit is contained in:
will
2020-06-27 17:33:02 +08:00
parent 7f9e664b90
commit b8218df789
5 changed files with 302 additions and 24 deletions

View File

@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"math/rand"
"strconv"
"github.com/mediocregopher/radix/v3"
@@ -69,26 +68,9 @@ func (r *RadixDriver) Connect(c Config) error {
}
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
}
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...)
}
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