2015-01-24 15:12:48 +03:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2018-03-07 16:39:56 +03:00
|
|
|
"context"
|
2018-05-11 09:46:09 +03:00
|
|
|
"crypto/tls"
|
2016-12-13 18:28:39 +03:00
|
|
|
"fmt"
|
2018-02-12 17:15:40 +03:00
|
|
|
"math"
|
2017-06-30 00:43:19 +03:00
|
|
|
"net"
|
2022-10-06 13:33:37 +03:00
|
|
|
"net/url"
|
2018-08-04 12:19:19 +03:00
|
|
|
"runtime"
|
2018-07-22 10:50:26 +03:00
|
|
|
"sort"
|
2022-10-06 13:33:37 +03:00
|
|
|
"strings"
|
2015-01-24 15:12:48 +03:00
|
|
|
"sync"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
2015-12-30 16:53:45 +03:00
|
|
|
|
2023-01-23 09:48:54 +03:00
|
|
|
"github.com/redis/go-redis/v9/internal"
|
|
|
|
"github.com/redis/go-redis/v9/internal/hashtag"
|
|
|
|
"github.com/redis/go-redis/v9/internal/pool"
|
|
|
|
"github.com/redis/go-redis/v9/internal/proto"
|
|
|
|
"github.com/redis/go-redis/v9/internal/rand"
|
2015-01-24 15:12:48 +03:00
|
|
|
)
|
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
var errClusterNoNodes = fmt.Errorf("redis: cluster has no nodes")
|
2016-10-09 14:12:32 +03:00
|
|
|
|
2016-10-09 13:30:45 +03:00
|
|
|
// ClusterOptions are used to configure a cluster client and should be
|
|
|
|
// passed to NewClusterClient.
|
|
|
|
type ClusterOptions struct {
|
|
|
|
// A seed list of host:port addresses of cluster nodes.
|
|
|
|
Addrs []string
|
|
|
|
|
2022-12-28 17:14:52 +03:00
|
|
|
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
|
|
|
|
ClientName string
|
|
|
|
|
2020-06-10 15:04:12 +03:00
|
|
|
// NewClient creates a cluster node client with provided name and options.
|
|
|
|
NewClient func(opt *Options) *Client
|
|
|
|
|
2016-10-09 13:30:45 +03:00
|
|
|
// The maximum number of retries before giving up. Command is retried
|
|
|
|
// on network errors and MOVED/ASK redirects.
|
2020-09-11 11:24:38 +03:00
|
|
|
// Default is 3 retries.
|
2016-10-09 13:30:45 +03:00
|
|
|
MaxRedirects int
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
// Enables read-only commands on slave nodes.
|
2016-10-09 13:30:45 +03:00
|
|
|
ReadOnly bool
|
2017-07-09 13:10:07 +03:00
|
|
|
// Allows routing read-only commands to the closest master or slave node.
|
2018-05-17 16:09:56 +03:00
|
|
|
// It automatically enables ReadOnly.
|
2016-10-09 13:30:45 +03:00
|
|
|
RouteByLatency bool
|
2018-03-07 13:23:38 +03:00
|
|
|
// Allows routing read-only commands to the random master or slave node.
|
2018-06-29 10:45:05 +03:00
|
|
|
// It automatically enables ReadOnly.
|
2018-03-07 13:23:38 +03:00
|
|
|
RouteRandomly bool
|
2016-10-09 13:30:45 +03:00
|
|
|
|
2018-07-18 15:28:51 +03:00
|
|
|
// Optional function that returns cluster slots information.
|
2018-06-29 10:45:05 +03:00
|
|
|
// It is useful to manually create cluster of standalone Redis servers
|
2018-07-18 15:28:51 +03:00
|
|
|
// and load-balance read/write operations between master and slaves.
|
|
|
|
// It can use service like ZooKeeper to maintain configuration information
|
|
|
|
// and Cluster.ReloadState to manually trigger state reloading.
|
2020-09-09 15:27:17 +03:00
|
|
|
ClusterSlots func(context.Context) ([]ClusterSlot, error)
|
2018-06-29 10:45:05 +03:00
|
|
|
|
2016-10-09 13:30:45 +03:00
|
|
|
// Following options are copied from Options struct.
|
|
|
|
|
2019-06-04 14:05:29 +03:00
|
|
|
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
2019-05-18 14:00:07 +03:00
|
|
|
|
2020-06-10 10:36:22 +03:00
|
|
|
OnConnect func(ctx context.Context, cn *Conn) error
|
2017-05-25 14:16:39 +03:00
|
|
|
|
2020-05-21 08:59:20 +03:00
|
|
|
Username string
|
2018-08-14 16:16:27 +03:00
|
|
|
Password string
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
MaxRetries int
|
|
|
|
MinRetryBackoff time.Duration
|
|
|
|
MaxRetryBackoff time.Duration
|
2016-10-09 13:30:45 +03:00
|
|
|
|
2022-10-11 10:22:42 +03:00
|
|
|
DialTimeout time.Duration
|
|
|
|
ReadTimeout time.Duration
|
|
|
|
WriteTimeout time.Duration
|
|
|
|
ContextTimeoutEnabled bool
|
2016-10-09 13:30:45 +03:00
|
|
|
|
2022-10-11 15:37:34 +03:00
|
|
|
PoolFIFO bool
|
|
|
|
PoolSize int // applies per cluster node and not for the whole cluster
|
2022-07-28 15:11:35 +03:00
|
|
|
PoolTimeout time.Duration
|
|
|
|
MinIdleConns int
|
|
|
|
MaxIdleConns int
|
|
|
|
ConnMaxIdleTime time.Duration
|
|
|
|
ConnMaxLifetime time.Duration
|
2018-05-11 09:46:09 +03:00
|
|
|
|
|
|
|
TLSConfig *tls.Config
|
2016-10-09 13:30:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (opt *ClusterOptions) init() {
|
|
|
|
if opt.MaxRedirects == -1 {
|
|
|
|
opt.MaxRedirects = 0
|
|
|
|
} else if opt.MaxRedirects == 0 {
|
2020-09-11 11:24:38 +03:00
|
|
|
opt.MaxRedirects = 3
|
2016-10-09 13:30:45 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 19:21:25 +03:00
|
|
|
if opt.RouteByLatency || opt.RouteRandomly {
|
2016-10-09 13:30:45 +03:00
|
|
|
opt.ReadOnly = true
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
|
2018-08-04 12:19:19 +03:00
|
|
|
if opt.PoolSize == 0 {
|
2021-07-02 15:56:25 +03:00
|
|
|
opt.PoolSize = 5 * runtime.GOMAXPROCS(0)
|
2018-08-04 12:19:19 +03:00
|
|
|
}
|
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
switch opt.ReadTimeout {
|
|
|
|
case -1:
|
|
|
|
opt.ReadTimeout = 0
|
|
|
|
case 0:
|
|
|
|
opt.ReadTimeout = 3 * time.Second
|
|
|
|
}
|
|
|
|
switch opt.WriteTimeout {
|
|
|
|
case -1:
|
|
|
|
opt.WriteTimeout = 0
|
|
|
|
case 0:
|
|
|
|
opt.WriteTimeout = opt.ReadTimeout
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:24:38 +03:00
|
|
|
if opt.MaxRetries == 0 {
|
|
|
|
opt.MaxRetries = -1
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
switch opt.MinRetryBackoff {
|
|
|
|
case -1:
|
|
|
|
opt.MinRetryBackoff = 0
|
|
|
|
case 0:
|
|
|
|
opt.MinRetryBackoff = 8 * time.Millisecond
|
|
|
|
}
|
|
|
|
switch opt.MaxRetryBackoff {
|
|
|
|
case -1:
|
|
|
|
opt.MaxRetryBackoff = 0
|
|
|
|
case 0:
|
|
|
|
opt.MaxRetryBackoff = 512 * time.Millisecond
|
|
|
|
}
|
2020-05-21 09:34:51 +03:00
|
|
|
|
|
|
|
if opt.NewClient == nil {
|
|
|
|
opt.NewClient = NewClient
|
|
|
|
}
|
2016-10-09 13:30:45 +03:00
|
|
|
}
|
|
|
|
|
2022-10-06 13:33:37 +03:00
|
|
|
// ParseClusterURL parses a URL into ClusterOptions that can be used to connect to Redis.
|
|
|
|
// The URL must be in the form:
|
2023-01-07 11:30:56 +03:00
|
|
|
//
|
|
|
|
// redis://<user>:<password>@<host>:<port>
|
|
|
|
// or
|
|
|
|
// rediss://<user>:<password>@<host>:<port>
|
|
|
|
//
|
2022-10-06 13:33:37 +03:00
|
|
|
// To add additional addresses, specify the query parameter, "addr" one or more times. e.g:
|
2023-01-07 11:30:56 +03:00
|
|
|
//
|
|
|
|
// redis://<user>:<password>@<host>:<port>?addr=<host2>:<port2>&addr=<host3>:<port3>
|
|
|
|
// or
|
|
|
|
// rediss://<user>:<password>@<host>:<port>?addr=<host2>:<port2>&addr=<host3>:<port3>
|
2022-10-06 13:33:37 +03:00
|
|
|
//
|
|
|
|
// Most Option fields can be set using query parameters, with the following restrictions:
|
2023-01-07 11:30:56 +03:00
|
|
|
// - field names are mapped using snake-case conversion: to set MaxRetries, use max_retries
|
|
|
|
// - only scalar type fields are supported (bool, int, time.Duration)
|
|
|
|
// - for time.Duration fields, values must be a valid input for time.ParseDuration();
|
|
|
|
// additionally a plain integer as value (i.e. without unit) is intepreted as seconds
|
|
|
|
// - to disable a duration field, use value less than or equal to 0; to use the default
|
|
|
|
// value, leave the value blank or remove the parameter
|
|
|
|
// - only the last value is interpreted if a parameter is given multiple times
|
|
|
|
// - fields "network", "addr", "username" and "password" can only be set using other
|
|
|
|
// URL attributes (scheme, host, userinfo, resp.), query paremeters using these
|
|
|
|
// names will be treated as unknown parameters
|
|
|
|
// - unknown parameter names will result in an error
|
|
|
|
//
|
2022-10-06 13:33:37 +03:00
|
|
|
// Example:
|
2023-01-07 11:30:56 +03:00
|
|
|
//
|
|
|
|
// redis://user:password@localhost:6789?dial_timeout=3&read_timeout=6s&addr=localhost:6790&addr=localhost:6791
|
|
|
|
// is equivalent to:
|
|
|
|
// &ClusterOptions{
|
|
|
|
// Addr: ["localhost:6789", "localhost:6790", "localhost:6791"]
|
|
|
|
// DialTimeout: 3 * time.Second, // no time unit = seconds
|
|
|
|
// ReadTimeout: 6 * time.Second,
|
|
|
|
// }
|
2022-10-06 13:33:37 +03:00
|
|
|
func ParseClusterURL(redisURL string) (*ClusterOptions, error) {
|
|
|
|
o := &ClusterOptions{}
|
|
|
|
|
|
|
|
u, err := url.Parse(redisURL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// add base URL to the array of addresses
|
|
|
|
// more addresses may be added through the URL params
|
|
|
|
h, p := getHostPortWithDefaults(u)
|
|
|
|
o.Addrs = append(o.Addrs, net.JoinHostPort(h, p))
|
|
|
|
|
|
|
|
// setup username, password, and other configurations
|
|
|
|
o, err = setupClusterConn(u, h, o)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// setupClusterConn gets the username and password from the URL and the query parameters.
|
|
|
|
func setupClusterConn(u *url.URL, host string, o *ClusterOptions) (*ClusterOptions, error) {
|
|
|
|
switch u.Scheme {
|
|
|
|
case "rediss":
|
|
|
|
o.TLSConfig = &tls.Config{ServerName: host}
|
|
|
|
fallthrough
|
|
|
|
case "redis":
|
|
|
|
o.Username, o.Password = getUserPassword(u)
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve the configuration from the query parameters
|
|
|
|
o, err := setupClusterQueryParams(u, o)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// setupClusterQueryParams converts query parameters in u to option value in o.
|
|
|
|
func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, error) {
|
|
|
|
q := queryOptions{q: u.Query()}
|
|
|
|
|
2022-12-28 17:14:52 +03:00
|
|
|
o.ClientName = q.string("client_name")
|
2022-10-06 13:33:37 +03:00
|
|
|
o.MaxRedirects = q.int("max_redirects")
|
|
|
|
o.ReadOnly = q.bool("read_only")
|
|
|
|
o.RouteByLatency = q.bool("route_by_latency")
|
2022-11-04 20:17:22 +03:00
|
|
|
o.RouteRandomly = q.bool("route_randomly")
|
2022-10-06 13:33:37 +03:00
|
|
|
o.MaxRetries = q.int("max_retries")
|
|
|
|
o.MinRetryBackoff = q.duration("min_retry_backoff")
|
|
|
|
o.MaxRetryBackoff = q.duration("max_retry_backoff")
|
|
|
|
o.DialTimeout = q.duration("dial_timeout")
|
|
|
|
o.ReadTimeout = q.duration("read_timeout")
|
|
|
|
o.WriteTimeout = q.duration("write_timeout")
|
|
|
|
o.PoolFIFO = q.bool("pool_fifo")
|
|
|
|
o.PoolSize = q.int("pool_size")
|
|
|
|
o.MinIdleConns = q.int("min_idle_conns")
|
|
|
|
o.PoolTimeout = q.duration("pool_timeout")
|
|
|
|
o.ConnMaxLifetime = q.duration("conn_max_lifetime")
|
|
|
|
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
|
|
|
|
|
|
|
|
if q.err != nil {
|
|
|
|
return nil, q.err
|
|
|
|
}
|
|
|
|
|
|
|
|
// addr can be specified as many times as needed
|
|
|
|
addrs := q.strings("addr")
|
|
|
|
for _, addr := range addrs {
|
|
|
|
h, p, err := net.SplitHostPort(addr)
|
|
|
|
if err != nil || h == "" || p == "" {
|
|
|
|
return nil, fmt.Errorf("redis: unable to parse addr param: %s", addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
o.Addrs = append(o.Addrs, net.JoinHostPort(h, p))
|
|
|
|
}
|
|
|
|
|
|
|
|
// any parameters left?
|
|
|
|
if r := q.remaining(); len(r) > 0 {
|
|
|
|
return nil, fmt.Errorf("redis: unexpected option: %s", strings.Join(r, ", "))
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
2016-10-09 13:30:45 +03:00
|
|
|
func (opt *ClusterOptions) clientOptions() *Options {
|
|
|
|
return &Options{
|
2022-12-28 17:14:52 +03:00
|
|
|
ClientName: opt.ClientName,
|
|
|
|
Dialer: opt.Dialer,
|
|
|
|
OnConnect: opt.OnConnect,
|
2017-05-25 14:16:39 +03:00
|
|
|
|
2020-09-11 11:24:38 +03:00
|
|
|
Username: opt.Username,
|
|
|
|
Password: opt.Password,
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
MaxRetries: opt.MaxRetries,
|
|
|
|
MinRetryBackoff: opt.MinRetryBackoff,
|
|
|
|
MaxRetryBackoff: opt.MaxRetryBackoff,
|
2016-10-09 13:30:45 +03:00
|
|
|
|
|
|
|
DialTimeout: opt.DialTimeout,
|
|
|
|
ReadTimeout: opt.ReadTimeout,
|
|
|
|
WriteTimeout: opt.WriteTimeout,
|
|
|
|
|
2022-07-28 15:11:35 +03:00
|
|
|
PoolFIFO: opt.PoolFIFO,
|
|
|
|
PoolSize: opt.PoolSize,
|
|
|
|
PoolTimeout: opt.PoolTimeout,
|
|
|
|
MinIdleConns: opt.MinIdleConns,
|
|
|
|
MaxIdleConns: opt.MaxIdleConns,
|
|
|
|
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
|
|
|
ConnMaxLifetime: opt.ConnMaxLifetime,
|
2018-05-11 09:46:09 +03:00
|
|
|
|
|
|
|
TLSConfig: opt.TLSConfig,
|
2020-12-11 19:21:25 +03:00
|
|
|
// If ClusterSlots is populated, then we probably have an artificial
|
|
|
|
// cluster whose nodes are not in clustering mode (otherwise there isn't
|
|
|
|
// much use for ClusterSlots config). This means we cannot execute the
|
|
|
|
// READONLY command against that node -- setting readOnly to false in such
|
|
|
|
// situations in the options below will prevent that from happening.
|
|
|
|
readOnly: opt.ReadOnly && opt.ClusterSlots == nil,
|
2016-10-09 13:30:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
type clusterNode struct {
|
2018-02-12 17:15:40 +03:00
|
|
|
Client *Client
|
2017-07-09 13:10:07 +03:00
|
|
|
|
2018-02-12 17:15:40 +03:00
|
|
|
latency uint32 // atomic
|
2018-02-15 14:00:54 +03:00
|
|
|
generation uint32 // atomic
|
2019-06-16 13:58:15 +03:00
|
|
|
failing uint32 // atomic
|
2016-10-09 11:18:57 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func newClusterNode(clOpt *ClusterOptions, addr string) *clusterNode {
|
|
|
|
opt := clOpt.clientOptions()
|
|
|
|
opt.Addr = addr
|
|
|
|
node := clusterNode{
|
2020-05-21 09:34:51 +03:00
|
|
|
Client: clOpt.NewClient(opt),
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 17:15:40 +03:00
|
|
|
node.latency = math.MaxUint32
|
2016-11-08 12:46:44 +03:00
|
|
|
if clOpt.RouteByLatency {
|
2018-02-12 17:15:40 +03:00
|
|
|
go node.updateLatency()
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return &node
|
|
|
|
}
|
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
func (n *clusterNode) String() string {
|
|
|
|
return n.Client.String()
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:00:54 +03:00
|
|
|
func (n *clusterNode) Close() error {
|
|
|
|
return n.Client.Close()
|
|
|
|
}
|
|
|
|
|
2016-12-16 17:26:48 +03:00
|
|
|
func (n *clusterNode) updateLatency() {
|
2020-09-11 12:24:09 +03:00
|
|
|
const numProbe = 10
|
|
|
|
var dur uint64
|
2018-02-12 17:15:40 +03:00
|
|
|
|
2022-07-01 17:14:52 +03:00
|
|
|
successes := 0
|
2020-09-11 12:24:09 +03:00
|
|
|
for i := 0; i < numProbe; i++ {
|
2020-09-11 12:46:38 +03:00
|
|
|
time.Sleep(time.Duration(10+rand.Intn(10)) * time.Millisecond)
|
2018-02-12 17:15:40 +03:00
|
|
|
|
2016-12-16 17:26:48 +03:00
|
|
|
start := time.Now()
|
2022-07-01 17:14:52 +03:00
|
|
|
err := n.Client.Ping(context.TODO()).Err()
|
|
|
|
if err == nil {
|
|
|
|
dur += uint64(time.Since(start) / time.Microsecond)
|
|
|
|
successes++
|
|
|
|
}
|
2016-12-16 17:26:48 +03:00
|
|
|
}
|
2020-09-11 12:24:09 +03:00
|
|
|
|
2022-07-01 17:14:52 +03:00
|
|
|
var latency float64
|
|
|
|
if successes == 0 {
|
|
|
|
// If none of the pings worked, set latency to some arbitrarily high value so this node gets
|
|
|
|
// least priority.
|
|
|
|
latency = float64((1 * time.Minute) / time.Microsecond)
|
|
|
|
} else {
|
|
|
|
latency = float64(dur) / float64(successes)
|
|
|
|
}
|
2020-09-11 12:24:09 +03:00
|
|
|
atomic.StoreUint32(&n.latency, uint32(latency+0.5))
|
2018-02-12 17:15:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *clusterNode) Latency() time.Duration {
|
|
|
|
latency := atomic.LoadUint32(&n.latency)
|
|
|
|
return time.Duration(latency) * time.Microsecond
|
|
|
|
}
|
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
func (n *clusterNode) MarkAsFailing() {
|
|
|
|
atomic.StoreUint32(&n.failing, uint32(time.Now().Unix()))
|
2016-12-16 17:26:48 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
func (n *clusterNode) Failing() bool {
|
|
|
|
const timeout = 15 // 15 seconds
|
2018-02-12 17:15:40 +03:00
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
failing := atomic.LoadUint32(&n.failing)
|
|
|
|
if failing == 0 {
|
2018-02-12 17:15:40 +03:00
|
|
|
return false
|
|
|
|
}
|
2019-06-16 13:58:15 +03:00
|
|
|
if time.Now().Unix()-int64(failing) < timeout {
|
2018-02-12 17:15:40 +03:00
|
|
|
return true
|
|
|
|
}
|
2019-06-16 13:58:15 +03:00
|
|
|
atomic.StoreUint32(&n.failing, 0)
|
2018-02-12 17:15:40 +03:00
|
|
|
return false
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
func (n *clusterNode) Generation() uint32 {
|
2018-02-15 14:00:54 +03:00
|
|
|
return atomic.LoadUint32(&n.generation)
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *clusterNode) SetGeneration(gen uint32) {
|
2018-02-15 14:00:54 +03:00
|
|
|
for {
|
|
|
|
v := atomic.LoadUint32(&n.generation)
|
|
|
|
if gen < v || atomic.CompareAndSwapUint32(&n.generation, v, gen) {
|
|
|
|
break
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
type clusterNodes struct {
|
2016-03-17 19:00:47 +03:00
|
|
|
opt *ClusterOptions
|
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
mu sync.RWMutex
|
|
|
|
addrs []string
|
|
|
|
nodes map[string]*clusterNode
|
|
|
|
activeAddrs []string
|
|
|
|
closed bool
|
2022-10-11 15:37:34 +03:00
|
|
|
onNewNode []func(rdb *Client)
|
2018-02-15 14:00:54 +03:00
|
|
|
|
2018-05-17 14:36:51 +03:00
|
|
|
_generation uint32 // atomic
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func newClusterNodes(opt *ClusterOptions) *clusterNodes {
|
|
|
|
return &clusterNodes{
|
2018-02-15 14:00:54 +03:00
|
|
|
opt: opt,
|
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
addrs: opt.Addrs,
|
|
|
|
nodes: make(map[string]*clusterNode),
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterNodes) Close() error {
|
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
2016-10-02 15:44:01 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
if c.closed {
|
|
|
|
return nil
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
2016-11-08 12:46:44 +03:00
|
|
|
c.closed = true
|
2016-05-06 21:12:31 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
var firstErr error
|
2020-07-09 11:35:13 +03:00
|
|
|
for _, node := range c.nodes {
|
2016-11-08 12:46:44 +03:00
|
|
|
if err := node.Client.Close(); err != nil && firstErr == nil {
|
|
|
|
firstErr = err
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
2016-10-09 13:30:45 +03:00
|
|
|
}
|
2018-02-15 14:00:54 +03:00
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
c.nodes = nil
|
|
|
|
c.activeAddrs = nil
|
2016-11-08 12:46:44 +03:00
|
|
|
|
|
|
|
return firstErr
|
2016-03-17 19:00:47 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 15:37:34 +03:00
|
|
|
func (c *clusterNodes) OnNewNode(fn func(rdb *Client)) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.onNewNode = append(c.onNewNode, fn)
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
2017-09-11 08:58:56 +03:00
|
|
|
func (c *clusterNodes) Addrs() ([]string, error) {
|
2018-02-15 14:00:54 +03:00
|
|
|
var addrs []string
|
2021-03-23 11:55:14 +03:00
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
c.mu.RLock()
|
2021-03-23 11:55:14 +03:00
|
|
|
closed := c.closed //nolint:ifshort
|
2018-02-15 14:00:54 +03:00
|
|
|
if !closed {
|
2020-07-09 11:35:13 +03:00
|
|
|
if len(c.activeAddrs) > 0 {
|
|
|
|
addrs = c.activeAddrs
|
2018-02-15 14:00:54 +03:00
|
|
|
} else {
|
2020-07-09 11:35:13 +03:00
|
|
|
addrs = c.addrs
|
2018-02-15 14:00:54 +03:00
|
|
|
}
|
|
|
|
}
|
2017-09-11 08:58:56 +03:00
|
|
|
c.mu.RUnlock()
|
2017-08-31 15:22:47 +03:00
|
|
|
|
2017-09-11 08:58:56 +03:00
|
|
|
if closed {
|
|
|
|
return nil, pool.ErrClosed
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
2017-09-11 08:58:56 +03:00
|
|
|
if len(addrs) == 0 {
|
|
|
|
return nil, errClusterNoNodes
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
2017-09-11 08:58:56 +03:00
|
|
|
return addrs, nil
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
func (c *clusterNodes) NextGeneration() uint32 {
|
2018-05-17 14:36:51 +03:00
|
|
|
return atomic.AddUint32(&c._generation, 1)
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GC removes unused nodes.
|
2018-01-17 13:55:20 +03:00
|
|
|
func (c *clusterNodes) GC(generation uint32) {
|
2019-07-25 13:53:00 +03:00
|
|
|
//nolint:prealloc
|
2017-07-09 13:10:07 +03:00
|
|
|
var collected []*clusterNode
|
2020-07-09 11:35:13 +03:00
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
c.mu.Lock()
|
2020-07-09 11:35:13 +03:00
|
|
|
|
|
|
|
c.activeAddrs = c.activeAddrs[:0]
|
|
|
|
for addr, node := range c.nodes {
|
2017-07-09 13:10:07 +03:00
|
|
|
if node.Generation() >= generation {
|
2020-07-09 11:35:13 +03:00
|
|
|
c.activeAddrs = append(c.activeAddrs, addr)
|
2020-09-11 12:24:09 +03:00
|
|
|
if c.opt.RouteByLatency {
|
|
|
|
go node.updateLatency()
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
delete(c.nodes, addr)
|
2017-07-09 13:10:07 +03:00
|
|
|
collected = append(collected, node)
|
|
|
|
}
|
2020-07-09 11:35:13 +03:00
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
c.mu.Unlock()
|
|
|
|
|
2018-02-27 15:35:03 +03:00
|
|
|
for _, node := range collected {
|
|
|
|
_ = node.Client.Close()
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) {
|
2019-06-29 10:28:33 +03:00
|
|
|
node, err := c.get(addr)
|
2018-02-27 15:35:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if node != nil {
|
2016-06-05 14:30:56 +03:00
|
|
|
return node, nil
|
2016-03-17 19:00:47 +03:00
|
|
|
}
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
c.mu.Lock()
|
2016-11-08 12:46:44 +03:00
|
|
|
defer c.mu.Unlock()
|
2016-06-05 14:30:56 +03:00
|
|
|
|
|
|
|
if c.closed {
|
|
|
|
return nil, pool.ErrClosed
|
|
|
|
}
|
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
node, ok := c.nodes[addr]
|
2016-11-08 12:46:44 +03:00
|
|
|
if ok {
|
2020-07-19 09:49:00 +03:00
|
|
|
return node, nil
|
2015-03-18 13:41:24 +03:00
|
|
|
}
|
2019-01-08 10:25:41 +03:00
|
|
|
|
|
|
|
node = newClusterNode(c.opt, addr)
|
2022-10-11 15:37:34 +03:00
|
|
|
for _, fn := range c.onNewNode {
|
|
|
|
fn(node.Client)
|
|
|
|
}
|
2015-03-18 13:41:24 +03:00
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
c.addrs = appendIfNotExists(c.addrs, addr)
|
|
|
|
c.nodes[addr] = node
|
2018-02-15 14:00:54 +03:00
|
|
|
|
2020-07-19 09:49:00 +03:00
|
|
|
return node, nil
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2019-06-29 10:28:33 +03:00
|
|
|
func (c *clusterNodes) get(addr string) (*clusterNode, error) {
|
|
|
|
var node *clusterNode
|
|
|
|
var err error
|
|
|
|
c.mu.RLock()
|
|
|
|
if c.closed {
|
|
|
|
err = pool.ErrClosed
|
|
|
|
} else {
|
2020-07-09 11:35:13 +03:00
|
|
|
node = c.nodes[addr]
|
2019-06-29 10:28:33 +03:00
|
|
|
}
|
|
|
|
c.mu.RUnlock()
|
|
|
|
return node, err
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
func (c *clusterNodes) All() ([]*clusterNode, error) {
|
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
|
|
if c.closed {
|
|
|
|
return nil, pool.ErrClosed
|
|
|
|
}
|
|
|
|
|
2020-07-09 11:35:13 +03:00
|
|
|
cp := make([]*clusterNode, 0, len(c.nodes))
|
|
|
|
for _, node := range c.nodes {
|
2018-03-06 18:10:01 +03:00
|
|
|
cp = append(cp, node)
|
|
|
|
}
|
|
|
|
return cp, nil
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterNodes) Random() (*clusterNode, error) {
|
2017-09-11 08:58:56 +03:00
|
|
|
addrs, err := c.Addrs()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:00:54 +03:00
|
|
|
n := rand.Intn(len(addrs))
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
return c.GetOrCreate(addrs[n])
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2018-07-22 10:50:26 +03:00
|
|
|
type clusterSlot struct {
|
|
|
|
start, end int
|
|
|
|
nodes []*clusterNode
|
|
|
|
}
|
|
|
|
|
|
|
|
type clusterSlotSlice []*clusterSlot
|
|
|
|
|
|
|
|
func (p clusterSlotSlice) Len() int {
|
|
|
|
return len(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p clusterSlotSlice) Less(i, j int) bool {
|
|
|
|
return p[i].start < p[j].start
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p clusterSlotSlice) Swap(i, j int) {
|
|
|
|
p[i], p[j] = p[j], p[i]
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
type clusterState struct {
|
2017-07-09 13:10:07 +03:00
|
|
|
nodes *clusterNodes
|
2018-05-17 16:09:56 +03:00
|
|
|
Masters []*clusterNode
|
|
|
|
Slaves []*clusterNode
|
2017-07-09 13:10:07 +03:00
|
|
|
|
2018-07-22 10:50:26 +03:00
|
|
|
slots []*clusterSlot
|
2017-07-09 13:10:07 +03:00
|
|
|
|
|
|
|
generation uint32
|
2018-05-21 16:33:41 +03:00
|
|
|
createdAt time.Time
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
func newClusterState(
|
|
|
|
nodes *clusterNodes, slots []ClusterSlot, origin string,
|
|
|
|
) (*clusterState, error) {
|
2016-11-08 12:46:44 +03:00
|
|
|
c := clusterState{
|
2018-05-21 16:33:41 +03:00
|
|
|
nodes: nodes,
|
2017-07-09 13:10:07 +03:00
|
|
|
|
2018-07-22 10:50:26 +03:00
|
|
|
slots: make([]*clusterSlot, 0, len(slots)),
|
2018-05-21 16:33:41 +03:00
|
|
|
|
|
|
|
generation: nodes.NextGeneration(),
|
|
|
|
createdAt: time.Now(),
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-08-14 15:56:43 +03:00
|
|
|
originHost, _, _ := net.SplitHostPort(origin)
|
|
|
|
isLoopbackOrigin := isLoopback(originHost)
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
for _, slot := range slots {
|
|
|
|
var nodes []*clusterNode
|
2017-07-09 13:10:07 +03:00
|
|
|
for i, slotNode := range slot.Nodes {
|
2017-06-30 00:43:19 +03:00
|
|
|
addr := slotNode.Addr
|
2018-08-14 15:56:43 +03:00
|
|
|
if !isLoopbackOrigin {
|
|
|
|
addr = replaceLoopbackHost(addr, originHost)
|
2017-06-30 00:43:19 +03:00
|
|
|
}
|
|
|
|
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err := c.nodes.GetOrCreate(addr)
|
2016-11-08 12:46:44 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
|
|
|
|
node.SetGeneration(c.generation)
|
2016-11-08 12:46:44 +03:00
|
|
|
nodes = append(nodes, node)
|
2017-07-09 13:10:07 +03:00
|
|
|
|
|
|
|
if i == 0 {
|
2018-05-17 16:09:56 +03:00
|
|
|
c.Masters = appendUniqueNode(c.Masters, node)
|
2017-07-09 13:10:07 +03:00
|
|
|
} else {
|
2018-05-17 16:09:56 +03:00
|
|
|
c.Slaves = appendUniqueNode(c.Slaves, node)
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-07-22 10:50:26 +03:00
|
|
|
c.slots = append(c.slots, &clusterSlot{
|
|
|
|
start: slot.Start,
|
|
|
|
end: slot.End,
|
|
|
|
nodes: nodes,
|
|
|
|
})
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
2018-07-22 10:50:26 +03:00
|
|
|
sort.Sort(clusterSlotSlice(c.slots))
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
time.AfterFunc(time.Minute, func() {
|
|
|
|
nodes.GC(c.generation)
|
|
|
|
})
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
return &c, nil
|
|
|
|
}
|
|
|
|
|
2018-08-14 15:56:43 +03:00
|
|
|
func replaceLoopbackHost(nodeAddr, originHost string) string {
|
|
|
|
nodeHost, nodePort, err := net.SplitHostPort(nodeAddr)
|
|
|
|
if err != nil {
|
|
|
|
return nodeAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeIP := net.ParseIP(nodeHost)
|
|
|
|
if nodeIP == nil {
|
|
|
|
return nodeAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if !nodeIP.IsLoopback() {
|
|
|
|
return nodeAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use origin host which is not loopback and node port.
|
|
|
|
return net.JoinHostPort(originHost, nodePort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func isLoopback(host string) bool {
|
|
|
|
ip := net.ParseIP(host)
|
|
|
|
if ip == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return ip.IsLoopback()
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterState) slotMasterNode(slot int) (*clusterNode, error) {
|
2016-05-06 21:12:31 +03:00
|
|
|
nodes := c.slotNodes(slot)
|
2016-12-16 15:05:21 +03:00
|
|
|
if len(nodes) > 0 {
|
|
|
|
return nodes[0], nil
|
2015-05-05 12:48:49 +03:00
|
|
|
}
|
2016-12-16 15:05:21 +03:00
|
|
|
return c.nodes.Random()
|
2015-05-05 12:48:49 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
|
2016-05-06 21:12:31 +03:00
|
|
|
nodes := c.slotNodes(slot)
|
|
|
|
switch len(nodes) {
|
|
|
|
case 0:
|
2016-11-08 12:46:44 +03:00
|
|
|
return c.nodes.Random()
|
2016-05-06 21:12:31 +03:00
|
|
|
case 1:
|
2016-06-05 14:30:56 +03:00
|
|
|
return nodes[0], nil
|
2016-05-06 21:12:31 +03:00
|
|
|
case 2:
|
2019-06-16 13:58:15 +03:00
|
|
|
if slave := nodes[1]; !slave.Failing() {
|
2016-10-09 11:18:57 +03:00
|
|
|
return slave, nil
|
|
|
|
}
|
|
|
|
return nodes[0], nil
|
2016-05-06 21:12:31 +03:00
|
|
|
default:
|
2016-10-09 11:18:57 +03:00
|
|
|
var slave *clusterNode
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
n := rand.Intn(len(nodes)-1) + 1
|
|
|
|
slave = nodes[n]
|
2019-06-16 13:58:15 +03:00
|
|
|
if !slave.Failing() {
|
2018-11-21 11:49:30 +03:00
|
|
|
return slave, nil
|
2016-10-09 11:18:57 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 11:49:30 +03:00
|
|
|
|
|
|
|
// All slaves are loading - use master.
|
|
|
|
return nodes[0], nil
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterState) slotClosestNode(slot int) (*clusterNode, error) {
|
2016-05-06 21:12:31 +03:00
|
|
|
nodes := c.slotNodes(slot)
|
2016-06-05 14:30:56 +03:00
|
|
|
if len(nodes) == 0 {
|
2016-11-08 12:46:44 +03:00
|
|
|
return c.nodes.Random()
|
2016-06-05 14:30:56 +03:00
|
|
|
}
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
var node *clusterNode
|
|
|
|
for _, n := range nodes {
|
2019-06-16 13:58:15 +03:00
|
|
|
if n.Failing() {
|
2016-12-16 17:26:48 +03:00
|
|
|
continue
|
|
|
|
}
|
2020-09-11 12:24:09 +03:00
|
|
|
if node == nil || n.Latency() < node.Latency() {
|
2016-05-06 21:12:31 +03:00
|
|
|
node = n
|
2015-04-04 16:46:57 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 18:04:04 +03:00
|
|
|
if node != nil {
|
|
|
|
return node, nil
|
|
|
|
}
|
2020-09-11 12:24:09 +03:00
|
|
|
|
2020-08-06 18:04:04 +03:00
|
|
|
// If all nodes are failing - return random node
|
|
|
|
return c.nodes.Random()
|
2015-04-04 16:46:57 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
func (c *clusterState) slotRandomNode(slot int) (*clusterNode, error) {
|
2018-03-07 13:23:38 +03:00
|
|
|
nodes := c.slotNodes(slot)
|
2019-06-16 13:58:15 +03:00
|
|
|
if len(nodes) == 0 {
|
|
|
|
return c.nodes.Random()
|
|
|
|
}
|
2021-07-17 19:20:48 +03:00
|
|
|
if len(nodes) == 1 {
|
|
|
|
return nodes[0], nil
|
|
|
|
}
|
|
|
|
randomNodes := rand.Perm(len(nodes))
|
|
|
|
for _, idx := range randomNodes {
|
|
|
|
if node := nodes[idx]; !node.Failing() {
|
|
|
|
return node, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes[randomNodes[0]], nil
|
2018-03-07 13:23:38 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
func (c *clusterState) slotNodes(slot int) []*clusterNode {
|
2018-07-22 10:50:26 +03:00
|
|
|
i := sort.Search(len(c.slots), func(i int) bool {
|
|
|
|
return c.slots[i].end >= slot
|
|
|
|
})
|
|
|
|
if i >= len(c.slots) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
x := c.slots[i]
|
|
|
|
if slot >= x.start && slot <= x.end {
|
|
|
|
return x.nodes
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
type clusterStateHolder struct {
|
2020-03-11 17:26:42 +03:00
|
|
|
load func(ctx context.Context) (*clusterState, error)
|
2018-03-06 18:10:01 +03:00
|
|
|
|
2018-12-13 13:26:02 +03:00
|
|
|
state atomic.Value
|
2018-03-07 15:38:18 +03:00
|
|
|
reloading uint32 // atomic
|
2018-03-06 18:10:01 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func newClusterStateHolder(fn func(ctx context.Context) (*clusterState, error)) *clusterStateHolder {
|
2018-03-06 18:10:01 +03:00
|
|
|
return &clusterStateHolder{
|
|
|
|
load: fn,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *clusterStateHolder) Reload(ctx context.Context) (*clusterState, error) {
|
|
|
|
state, err := c.load(ctx)
|
2018-03-06 18:10:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
c.state.Store(state)
|
|
|
|
return state, nil
|
|
|
|
}
|
|
|
|
|
2021-03-05 14:53:15 +03:00
|
|
|
func (c *clusterStateHolder) LazyReload() {
|
2018-03-06 18:10:01 +03:00
|
|
|
if !atomic.CompareAndSwapUint32(&c.reloading, 0, 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
defer atomic.StoreUint32(&c.reloading, 0)
|
|
|
|
|
2021-03-05 14:53:15 +03:00
|
|
|
_, err := c.Reload(context.Background())
|
2018-11-24 14:16:21 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
2018-03-06 18:10:01 +03:00
|
|
|
}
|
2020-07-09 10:39:46 +03:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
2018-03-06 18:10:01 +03:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *clusterStateHolder) Get(ctx context.Context) (*clusterState, error) {
|
2018-03-06 18:10:01 +03:00
|
|
|
v := c.state.Load()
|
2021-03-23 11:55:14 +03:00
|
|
|
if v == nil {
|
|
|
|
return c.Reload(ctx)
|
2018-03-06 18:10:01 +03:00
|
|
|
}
|
2021-03-23 11:55:14 +03:00
|
|
|
|
|
|
|
state := v.(*clusterState)
|
|
|
|
if time.Since(state.createdAt) > 10*time.Second {
|
|
|
|
c.LazyReload()
|
|
|
|
}
|
|
|
|
return state, nil
|
2018-03-06 18:10:01 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *clusterStateHolder) ReloadOrGet(ctx context.Context) (*clusterState, error) {
|
|
|
|
state, err := c.Reload(ctx)
|
2018-06-29 10:45:05 +03:00
|
|
|
if err == nil {
|
|
|
|
return state, nil
|
|
|
|
}
|
2020-03-11 17:26:42 +03:00
|
|
|
return c.Get(ctx)
|
2018-06-29 10:45:05 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-05-31 17:03:20 +03:00
|
|
|
// ClusterClient is a Redis Cluster client representing a pool of zero
|
|
|
|
// or more underlying connections. It's safe for concurrent use by
|
|
|
|
// multiple goroutines.
|
|
|
|
type ClusterClient struct {
|
2022-10-11 15:37:34 +03:00
|
|
|
opt *ClusterOptions
|
|
|
|
nodes *clusterNodes
|
|
|
|
state *clusterStateHolder
|
|
|
|
cmdsInfoCache *cmdsInfoCache
|
2019-08-24 12:22:52 +03:00
|
|
|
cmdable
|
2023-01-21 11:30:02 +03:00
|
|
|
hooksMixin
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClusterClient returns a Redis Cluster client as described in
|
|
|
|
// http://redis.io/topics/cluster-spec.
|
|
|
|
func NewClusterClient(opt *ClusterOptions) *ClusterClient {
|
|
|
|
opt.init()
|
|
|
|
|
|
|
|
c := &ClusterClient{
|
2022-10-11 15:37:34 +03:00
|
|
|
opt: opt,
|
|
|
|
nodes: newClusterNodes(opt),
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
2022-10-11 15:37:34 +03:00
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
c.state = newClusterStateHolder(c.loadState)
|
2018-05-17 15:21:51 +03:00
|
|
|
c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
|
2019-08-24 12:22:52 +03:00
|
|
|
c.cmdable = c.Process
|
2018-01-20 13:26:33 +03:00
|
|
|
|
2023-01-21 11:30:02 +03:00
|
|
|
c.initHooks(hooks{
|
2023-01-20 18:19:49 +03:00
|
|
|
dial: nil,
|
|
|
|
process: c.process,
|
|
|
|
pipeline: c.processPipeline,
|
|
|
|
txPipeline: c.processTxPipeline,
|
|
|
|
})
|
2022-10-11 15:37:34 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2017-03-20 13:15:21 +03:00
|
|
|
// Options returns read-only Options that were used to create the client.
|
|
|
|
func (c *ClusterClient) Options() *ClusterOptions {
|
|
|
|
return c.opt
|
|
|
|
}
|
|
|
|
|
2019-05-31 16:36:57 +03:00
|
|
|
// ReloadState reloads cluster state. If available it calls ClusterSlots func
|
|
|
|
// to get cluster slots information.
|
2020-09-11 15:52:38 +03:00
|
|
|
func (c *ClusterClient) ReloadState(ctx context.Context) {
|
2021-03-05 14:53:15 +03:00
|
|
|
c.state.LazyReload()
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes the cluster client, releasing any open resources.
|
|
|
|
//
|
|
|
|
// It is rare to Close a ClusterClient, as the ClusterClient is meant
|
|
|
|
// to be long-lived and shared between many goroutines.
|
|
|
|
func (c *ClusterClient) Close() error {
|
|
|
|
return c.nodes.Close()
|
|
|
|
}
|
|
|
|
|
2022-12-28 17:14:52 +03:00
|
|
|
// Do create a Cmd from the args and processes the cmd.
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) Do(ctx context.Context, args ...interface{}) *Cmd {
|
|
|
|
cmd := NewCmd(ctx, args...)
|
|
|
|
_ = c.Process(ctx, cmd)
|
2018-08-12 11:11:01 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error {
|
2023-01-21 11:30:02 +03:00
|
|
|
err := c.processHook(ctx, cmd)
|
2022-10-11 15:37:34 +03:00
|
|
|
cmd.SetErr(err)
|
|
|
|
return err
|
2018-01-20 13:26:33 +03:00
|
|
|
}
|
|
|
|
|
2019-06-04 13:30:47 +03:00
|
|
|
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
|
2022-07-14 13:43:42 +03:00
|
|
|
cmdInfo := c.cmdInfo(ctx, cmd.Name())
|
|
|
|
slot := c.cmdSlot(ctx, cmd)
|
2018-02-27 15:50:08 +03:00
|
|
|
var node *clusterNode
|
2016-06-17 15:09:38 +03:00
|
|
|
var ask bool
|
2019-08-08 16:54:38 +03:00
|
|
|
var lastErr error
|
2016-06-05 14:10:30 +03:00
|
|
|
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
|
2017-07-09 13:10:07 +03:00
|
|
|
if attempt > 0 {
|
2019-07-30 12:13:00 +03:00
|
|
|
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
2018-02-27 15:50:08 +03:00
|
|
|
if node == nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
var err error
|
2020-03-11 17:26:42 +03:00
|
|
|
node, err = c.cmdNode(ctx, cmdInfo, slot)
|
2018-02-27 15:50:08 +03:00
|
|
|
if err != nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
return err
|
2018-02-27 15:50:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
if ask {
|
2022-10-11 15:37:34 +03:00
|
|
|
ask = false
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
pipe := node.Client.Pipeline()
|
2020-03-11 17:26:42 +03:00
|
|
|
_ = pipe.Process(ctx, NewCmd(ctx, "asking"))
|
|
|
|
_ = pipe.Process(ctx, cmd)
|
|
|
|
_, lastErr = pipe.Exec(ctx)
|
2015-01-24 15:12:48 +03:00
|
|
|
} else {
|
2020-03-11 17:26:42 +03:00
|
|
|
lastErr = node.Client.Process(ctx, cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
// If there is no error - we are done.
|
2019-08-08 16:54:38 +03:00
|
|
|
if lastErr == nil {
|
|
|
|
return nil
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
2020-06-30 11:13:15 +03:00
|
|
|
if isReadOnly := isReadOnlyError(lastErr); isReadOnly || lastErr == pool.ErrClosed {
|
|
|
|
if isReadOnly {
|
2021-03-05 14:53:15 +03:00
|
|
|
c.state.LazyReload()
|
2020-06-30 11:13:15 +03:00
|
|
|
}
|
2019-08-08 16:54:38 +03:00
|
|
|
node = nil
|
|
|
|
continue
|
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2018-11-21 11:49:30 +03:00
|
|
|
// If slave is loading - pick another node.
|
2019-08-08 16:54:38 +03:00
|
|
|
if c.opt.ReadOnly && isLoadingError(lastErr) {
|
2019-06-16 13:58:15 +03:00
|
|
|
node.MarkAsFailing()
|
2018-11-21 11:49:30 +03:00
|
|
|
node = nil
|
2016-10-09 11:18:57 +03:00
|
|
|
continue
|
2016-10-09 06:30:01 +03:00
|
|
|
}
|
|
|
|
|
2015-03-18 13:41:24 +03:00
|
|
|
var moved bool
|
|
|
|
var addr string
|
2019-08-08 16:54:38 +03:00
|
|
|
moved, ask, addr = isMovedError(lastErr)
|
2015-03-18 13:41:24 +03:00
|
|
|
if moved || ask {
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
c.state.LazyReload()
|
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
var err error
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err = c.nodes.GetOrCreate(addr)
|
2018-02-27 15:50:08 +03:00
|
|
|
if err != nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
return err
|
2016-06-17 15:09:38 +03:00
|
|
|
}
|
2015-03-18 13:41:24 +03:00
|
|
|
continue
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2020-07-24 14:57:12 +03:00
|
|
|
if shouldRetry(lastErr, cmd.readTimeout() == nil) {
|
2019-01-08 17:37:22 +03:00
|
|
|
// First retry the same node.
|
|
|
|
if attempt == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
// Second try another node.
|
|
|
|
node.MarkAsFailing()
|
|
|
|
node = nil
|
2019-01-08 17:37:22 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
return lastErr
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
2019-08-08 16:54:38 +03:00
|
|
|
return lastErr
|
2016-06-17 15:09:38 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 15:37:34 +03:00
|
|
|
func (c *ClusterClient) OnNewNode(fn func(rdb *Client)) {
|
|
|
|
c.nodes.OnNewNode(fn)
|
|
|
|
}
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
// ForEachMaster concurrently calls the fn on each master node in the cluster.
|
2016-12-12 18:30:08 +03:00
|
|
|
// It returns the first error if any.
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) ForEachMaster(
|
|
|
|
ctx context.Context,
|
|
|
|
fn func(ctx context.Context, client *Client) error,
|
|
|
|
) error {
|
|
|
|
state, err := c.state.ReloadOrGet(ctx)
|
2017-08-31 15:22:47 +03:00
|
|
|
if err != nil {
|
2018-06-29 10:45:05 +03:00
|
|
|
return err
|
2016-12-12 18:30:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
errCh := make(chan error, 1)
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, master := range state.Masters {
|
2016-12-12 18:30:08 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go func(node *clusterNode) {
|
|
|
|
defer wg.Done()
|
2020-03-11 17:26:42 +03:00
|
|
|
err := fn(ctx, node.Client)
|
2016-12-12 18:30:08 +03:00
|
|
|
if err != nil {
|
|
|
|
select {
|
|
|
|
case errCh <- err:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
}(master)
|
2016-12-12 18:30:08 +03:00
|
|
|
}
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2016-12-12 18:30:08 +03:00
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-errCh:
|
|
|
|
return err
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
// ForEachSlave concurrently calls the fn on each slave node in the cluster.
|
2016-06-17 15:09:38 +03:00
|
|
|
// It returns the first error if any.
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) ForEachSlave(
|
|
|
|
ctx context.Context,
|
|
|
|
fn func(ctx context.Context, client *Client) error,
|
|
|
|
) error {
|
|
|
|
state, err := c.state.ReloadOrGet(ctx)
|
2017-08-31 15:22:47 +03:00
|
|
|
if err != nil {
|
2018-06-29 10:45:05 +03:00
|
|
|
return err
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|
2016-06-17 15:09:38 +03:00
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
2016-10-02 15:44:01 +03:00
|
|
|
errCh := make(chan error, 1)
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, slave := range state.Slaves {
|
2016-06-17 15:09:38 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go func(node *clusterNode) {
|
2016-10-02 15:44:01 +03:00
|
|
|
defer wg.Done()
|
2020-03-11 17:26:42 +03:00
|
|
|
err := fn(ctx, node.Client)
|
2016-06-17 15:09:38 +03:00
|
|
|
if err != nil {
|
2016-10-02 15:44:01 +03:00
|
|
|
select {
|
|
|
|
case errCh <- err:
|
|
|
|
default:
|
2016-06-17 15:09:38 +03:00
|
|
|
}
|
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
}(slave)
|
2016-06-17 15:09:38 +03:00
|
|
|
}
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2016-06-17 15:09:38 +03:00
|
|
|
wg.Wait()
|
|
|
|
|
2016-10-02 15:44:01 +03:00
|
|
|
select {
|
|
|
|
case err := <-errCh:
|
|
|
|
return err
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2020-06-10 15:04:12 +03:00
|
|
|
// ForEachShard concurrently calls the fn on each known node in the cluster.
|
2017-07-09 13:10:07 +03:00
|
|
|
// It returns the first error if any.
|
2020-06-10 15:04:12 +03:00
|
|
|
func (c *ClusterClient) ForEachShard(
|
2020-03-11 17:26:42 +03:00
|
|
|
ctx context.Context,
|
|
|
|
fn func(ctx context.Context, client *Client) error,
|
|
|
|
) error {
|
|
|
|
state, err := c.state.ReloadOrGet(ctx)
|
2017-08-31 15:22:47 +03:00
|
|
|
if err != nil {
|
2018-06-29 10:45:05 +03:00
|
|
|
return err
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
errCh := make(chan error, 1)
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
worker := func(node *clusterNode) {
|
|
|
|
defer wg.Done()
|
2020-03-11 17:26:42 +03:00
|
|
|
err := fn(ctx, node.Client)
|
2017-07-09 13:10:07 +03:00
|
|
|
if err != nil {
|
|
|
|
select {
|
|
|
|
case errCh <- err:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, node := range state.Masters {
|
2017-07-09 13:10:07 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go worker(node)
|
|
|
|
}
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, node := range state.Slaves {
|
2017-07-09 13:10:07 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go worker(node)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
select {
|
|
|
|
case err := <-errCh:
|
|
|
|
return err
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
// PoolStats returns accumulated connection pool stats.
|
|
|
|
func (c *ClusterClient) PoolStats() *PoolStats {
|
2017-03-04 14:04:27 +03:00
|
|
|
var acc PoolStats
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
state, _ := c.state.Get(context.TODO())
|
2017-07-09 13:10:07 +03:00
|
|
|
if state == nil {
|
2017-03-04 14:04:27 +03:00
|
|
|
return &acc
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
2016-04-09 12:52:43 +03:00
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, node := range state.Masters {
|
2017-07-09 13:10:07 +03:00
|
|
|
s := node.Client.connPool.Stats()
|
|
|
|
acc.Hits += s.Hits
|
2017-09-22 12:23:46 +03:00
|
|
|
acc.Misses += s.Misses
|
2017-07-09 13:10:07 +03:00
|
|
|
acc.Timeouts += s.Timeouts
|
2017-09-11 09:10:17 +03:00
|
|
|
|
2017-07-09 13:10:07 +03:00
|
|
|
acc.TotalConns += s.TotalConns
|
2018-08-12 10:08:21 +03:00
|
|
|
acc.IdleConns += s.IdleConns
|
2017-09-11 09:10:17 +03:00
|
|
|
acc.StaleConns += s.StaleConns
|
2017-07-09 13:10:07 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
for _, node := range state.Slaves {
|
2016-11-08 12:46:44 +03:00
|
|
|
s := node.Client.connPool.Stats()
|
|
|
|
acc.Hits += s.Hits
|
2017-09-22 12:23:46 +03:00
|
|
|
acc.Misses += s.Misses
|
2016-11-08 12:46:44 +03:00
|
|
|
acc.Timeouts += s.Timeouts
|
2017-09-11 09:10:17 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
acc.TotalConns += s.TotalConns
|
2018-08-12 10:08:21 +03:00
|
|
|
acc.IdleConns += s.IdleConns
|
2017-09-11 09:10:17 +03:00
|
|
|
acc.StaleConns += s.StaleConns
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
2017-07-09 13:10:07 +03:00
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
return &acc
|
2016-05-06 21:12:31 +03:00
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) loadState(ctx context.Context) (*clusterState, error) {
|
2018-06-29 10:45:05 +03:00
|
|
|
if c.opt.ClusterSlots != nil {
|
2020-09-09 15:27:17 +03:00
|
|
|
slots, err := c.opt.ClusterSlots(ctx)
|
2018-06-29 10:45:05 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return newClusterState(c.nodes, slots, "")
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
addrs, err := c.nodes.Addrs()
|
2017-03-04 14:04:27 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
var firstErr error
|
2020-07-09 11:35:13 +03:00
|
|
|
|
2020-06-29 17:26:11 +03:00
|
|
|
for _, idx := range rand.Perm(len(addrs)) {
|
|
|
|
addr := addrs[idx]
|
|
|
|
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err := c.nodes.GetOrCreate(addr)
|
2018-03-06 18:10:01 +03:00
|
|
|
if err != nil {
|
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2017-03-04 14:04:27 +03:00
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
slots, err := node.Client.ClusterSlots(ctx).Result()
|
2018-03-06 18:10:01 +03:00
|
|
|
if err != nil {
|
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
return newClusterState(c.nodes, slots, node.Client.opt.Addr)
|
2018-02-15 14:00:54 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 10:24:18 +03:00
|
|
|
/*
|
|
|
|
* No node is connectable. It's possible that all nodes' IP has changed.
|
2020-07-09 11:35:13 +03:00
|
|
|
* Clear activeAddrs to let client be able to re-connect using the initial
|
|
|
|
* setting of the addresses (e.g. [redis-cluster-0:6379, redis-cluster-1:6379]),
|
2020-06-15 10:24:18 +03:00
|
|
|
* which might have chance to resolve domain name and get updated IP address.
|
|
|
|
*/
|
|
|
|
c.nodes.mu.Lock()
|
2020-07-09 11:35:13 +03:00
|
|
|
c.nodes.activeAddrs = nil
|
2020-06-15 10:24:18 +03:00
|
|
|
c.nodes.mu.Unlock()
|
|
|
|
|
2018-03-06 18:10:01 +03:00
|
|
|
return nil, firstErr
|
2018-02-15 14:00:54 +03:00
|
|
|
}
|
|
|
|
|
2017-05-02 18:00:53 +03:00
|
|
|
func (c *ClusterClient) Pipeline() Pipeliner {
|
2016-06-05 12:45:39 +03:00
|
|
|
pipe := Pipeline{
|
2023-01-21 11:30:02 +03:00
|
|
|
exec: pipelineExecer(c.processPipelineHook),
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
2019-05-31 17:03:20 +03:00
|
|
|
pipe.init()
|
2016-06-05 12:45:39 +03:00
|
|
|
return &pipe
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {
|
|
|
|
return c.Pipeline().Pipelined(ctx, fn)
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
func (c *ClusterClient) processPipeline(ctx context.Context, cmds []Cmder) error {
|
2018-09-11 13:09:16 +03:00
|
|
|
cmdsMap := newCmdsMap()
|
2022-10-06 14:05:55 +03:00
|
|
|
|
|
|
|
if err := c.mapCmdsByNode(ctx, cmdsMap, cmds); err != nil {
|
2017-08-31 15:22:47 +03:00
|
|
|
setCmdsErr(cmds, err)
|
2016-12-13 18:28:39 +03:00
|
|
|
return err
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
|
|
|
|
if attempt > 0 {
|
2019-07-30 12:13:00 +03:00
|
|
|
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
setCmdsErr(cmds, err)
|
2019-07-30 12:13:00 +03:00
|
|
|
return err
|
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
|
|
|
|
2018-09-11 13:09:16 +03:00
|
|
|
failedCmds := newCmdsMap()
|
2018-09-11 12:37:57 +03:00
|
|
|
var wg sync.WaitGroup
|
2018-09-11 13:09:16 +03:00
|
|
|
|
|
|
|
for node, cmds := range cmdsMap.m {
|
2018-09-11 12:37:57 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go func(node *clusterNode, cmds []Cmder) {
|
|
|
|
defer wg.Done()
|
2022-11-21 12:55:19 +03:00
|
|
|
c.processPipelineNode(ctx, node, cmds, failedCmds)
|
2018-09-11 12:37:57 +03:00
|
|
|
}(node, cmds)
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-11 13:09:16 +03:00
|
|
|
wg.Wait()
|
|
|
|
if len(failedCmds.m) == 0 {
|
2016-12-13 18:28:39 +03:00
|
|
|
break
|
|
|
|
}
|
2016-04-09 10:47:15 +03:00
|
|
|
cmdsMap = failedCmds
|
|
|
|
}
|
|
|
|
|
2018-08-12 11:11:01 +03:00
|
|
|
return cmdsFirstErr(cmds)
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmds []Cmder) error {
|
|
|
|
state, err := c.state.Get(ctx)
|
2017-08-31 15:22:47 +03:00
|
|
|
if err != nil {
|
2018-09-11 13:09:16 +03:00
|
|
|
return err
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
if c.opt.ReadOnly && c.cmdsAreReadOnly(ctx, cmds) {
|
2020-02-02 14:01:57 +03:00
|
|
|
for _, cmd := range cmds {
|
2022-07-14 13:43:42 +03:00
|
|
|
slot := c.cmdSlot(ctx, cmd)
|
2020-02-02 14:01:57 +03:00
|
|
|
node, err := c.slotReadOnlyNode(state, slot)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cmdsMap.Add(node, cmd)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
for _, cmd := range cmds {
|
2022-07-14 13:43:42 +03:00
|
|
|
slot := c.cmdSlot(ctx, cmd)
|
2020-02-02 14:01:57 +03:00
|
|
|
node, err := state.slotMasterNode(slot)
|
2016-12-13 18:28:39 +03:00
|
|
|
if err != nil {
|
2018-09-11 13:09:16 +03:00
|
|
|
return err
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2019-08-08 16:54:38 +03:00
|
|
|
cmdsMap.Add(node, cmd)
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2018-09-11 13:09:16 +03:00
|
|
|
return nil
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
func (c *ClusterClient) cmdsAreReadOnly(ctx context.Context, cmds []Cmder) bool {
|
2018-05-31 21:40:56 +03:00
|
|
|
for _, cmd := range cmds {
|
2022-07-14 13:43:42 +03:00
|
|
|
cmdInfo := c.cmdInfo(ctx, cmd.Name())
|
2018-05-31 21:40:56 +03:00
|
|
|
if cmdInfo == nil || !cmdInfo.ReadOnly {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
func (c *ClusterClient) processPipelineNode(
|
2020-02-14 15:30:07 +03:00
|
|
|
ctx context.Context, node *clusterNode, cmds []Cmder, failedCmds *cmdsMap,
|
2022-10-06 14:05:55 +03:00
|
|
|
) {
|
2023-01-21 11:30:02 +03:00
|
|
|
_ = node.Client.withProcessPipelineHook(ctx, cmds, func(ctx context.Context, cmds []Cmder) error {
|
2022-11-21 12:55:19 +03:00
|
|
|
cn, err := node.Client.getConn(ctx)
|
|
|
|
if err != nil {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
|
|
|
setCmdsErr(cmds, err)
|
|
|
|
return err
|
|
|
|
}
|
2020-02-14 15:30:07 +03:00
|
|
|
|
2023-01-28 10:44:06 +03:00
|
|
|
var processErr error
|
|
|
|
defer func() {
|
|
|
|
node.Client.releaseConn(ctx, cn, processErr)
|
|
|
|
}()
|
|
|
|
processErr = c.processPipelineNodeConn(ctx, node, cn, cmds, failedCmds)
|
|
|
|
|
|
|
|
return processErr
|
2022-11-21 12:55:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClusterClient) processPipelineNodeConn(
|
|
|
|
ctx context.Context, node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds *cmdsMap,
|
|
|
|
) error {
|
|
|
|
if err := cn.WithWriter(c.context(ctx), c.opt.WriteTimeout, func(wr *proto.Writer) error {
|
|
|
|
return writeCmds(wr, cmds)
|
|
|
|
}); err != nil {
|
|
|
|
if shouldRetry(err, true) {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
|
|
|
}
|
|
|
|
setCmdsErr(cmds, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cn.WithReader(c.context(ctx), c.opt.ReadTimeout, func(rd *proto.Reader) error {
|
|
|
|
return c.pipelineReadCmds(ctx, node, rd, cmds, failedCmds)
|
2020-02-14 15:30:07 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
func (c *ClusterClient) pipelineReadCmds(
|
2020-03-11 17:26:42 +03:00
|
|
|
ctx context.Context,
|
|
|
|
node *clusterNode,
|
|
|
|
rd *proto.Reader,
|
|
|
|
cmds []Cmder,
|
|
|
|
failedCmds *cmdsMap,
|
2016-12-13 18:28:39 +03:00
|
|
|
) error {
|
2022-10-06 14:05:55 +03:00
|
|
|
for i, cmd := range cmds {
|
2018-08-15 09:38:58 +03:00
|
|
|
err := cmd.readReply(rd)
|
2020-09-17 12:27:16 +03:00
|
|
|
cmd.SetErr(err)
|
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
if err == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-09-17 12:27:16 +03:00
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
if c.checkMovedErr(ctx, cmd, err, failedCmds) {
|
2017-08-31 15:22:47 +03:00
|
|
|
continue
|
2016-06-05 14:30:56 +03:00
|
|
|
}
|
2016-12-13 18:28:39 +03:00
|
|
|
|
2022-10-06 14:05:55 +03:00
|
|
|
if c.opt.ReadOnly {
|
2019-06-16 13:58:15 +03:00
|
|
|
node.MarkAsFailing()
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
|
|
|
|
if !isRedisError(err) {
|
|
|
|
if shouldRetry(err, true) {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
|
|
|
}
|
|
|
|
setCmdsErr(cmds[i+1:], err)
|
|
|
|
return err
|
2018-12-13 14:27:41 +03:00
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := cmds[0].Err(); err != nil && shouldRetry(err, true) {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
2019-08-08 16:54:38 +03:00
|
|
|
return err
|
2016-06-05 14:30:56 +03:00
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
return nil
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2016-06-05 14:30:56 +03:00
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
func (c *ClusterClient) checkMovedErr(
|
2020-03-11 17:26:42 +03:00
|
|
|
ctx context.Context, cmd Cmder, err error, failedCmds *cmdsMap,
|
2017-08-31 15:22:47 +03:00
|
|
|
) bool {
|
2019-08-03 17:21:12 +03:00
|
|
|
moved, ask, addr := isMovedError(err)
|
2019-08-08 16:54:38 +03:00
|
|
|
if !moved && !ask {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err := c.nodes.GetOrCreate(addr)
|
2019-08-08 16:54:38 +03:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
if moved {
|
2021-03-05 14:53:15 +03:00
|
|
|
c.state.LazyReload()
|
2019-08-08 16:54:38 +03:00
|
|
|
failedCmds.Add(node, cmd)
|
2017-08-31 15:22:47 +03:00
|
|
|
return true
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
if ask {
|
2020-03-11 17:26:42 +03:00
|
|
|
failedCmds.Add(node, NewCmd(ctx, "asking"), cmd)
|
2017-08-31 15:22:47 +03:00
|
|
|
return true
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
panic("not reached")
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
|
|
|
|
2016-12-16 15:19:53 +03:00
|
|
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
2017-05-02 18:00:53 +03:00
|
|
|
func (c *ClusterClient) TxPipeline() Pipeliner {
|
2016-12-13 18:28:39 +03:00
|
|
|
pipe := Pipeline{
|
2022-10-11 15:37:34 +03:00
|
|
|
exec: func(ctx context.Context, cmds []Cmder) error {
|
|
|
|
cmds = wrapMultiExec(ctx, cmds)
|
2023-01-21 11:30:02 +03:00
|
|
|
return c.processTxPipelineHook(ctx, cmds)
|
2022-10-11 15:37:34 +03:00
|
|
|
},
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2019-05-31 17:03:20 +03:00
|
|
|
pipe.init()
|
2016-12-13 18:28:39 +03:00
|
|
|
return &pipe
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {
|
|
|
|
return c.TxPipeline().Pipelined(ctx, fn)
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) error {
|
2021-01-09 10:27:42 +03:00
|
|
|
// Trim multi .. exec.
|
|
|
|
cmds = cmds[1 : len(cmds)-1]
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
state, err := c.state.Get(ctx)
|
2016-12-13 18:28:39 +03:00
|
|
|
if err != nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
setCmdsErr(cmds, err)
|
2016-12-13 18:28:39 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
cmdsMap := c.mapCmdsBySlot(ctx, cmds)
|
2016-12-13 18:28:39 +03:00
|
|
|
for slot, cmds := range cmdsMap {
|
2017-03-04 14:04:27 +03:00
|
|
|
node, err := state.slotMasterNode(slot)
|
2016-12-13 18:28:39 +03:00
|
|
|
if err != nil {
|
|
|
|
setCmdsErr(cmds, err)
|
2016-04-09 10:47:15 +03:00
|
|
|
continue
|
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
cmdsMap := map[*clusterNode][]Cmder{node: cmds}
|
2017-08-31 15:22:47 +03:00
|
|
|
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
|
|
|
|
if attempt > 0 {
|
2019-07-30 12:13:00 +03:00
|
|
|
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
|
2019-08-08 16:54:38 +03:00
|
|
|
setCmdsErr(cmds, err)
|
2019-07-30 12:13:00 +03:00
|
|
|
return err
|
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
}
|
|
|
|
|
2018-09-11 13:09:16 +03:00
|
|
|
failedCmds := newCmdsMap()
|
|
|
|
var wg sync.WaitGroup
|
2016-12-13 18:28:39 +03:00
|
|
|
|
|
|
|
for node, cmds := range cmdsMap {
|
2018-09-11 13:09:16 +03:00
|
|
|
wg.Add(1)
|
|
|
|
go func(node *clusterNode, cmds []Cmder) {
|
|
|
|
defer wg.Done()
|
2022-11-21 12:55:19 +03:00
|
|
|
c.processTxPipelineNode(ctx, node, cmds, failedCmds)
|
2018-09-11 13:09:16 +03:00
|
|
|
}(node, cmds)
|
2016-12-12 18:30:08 +03:00
|
|
|
}
|
|
|
|
|
2018-09-11 13:09:16 +03:00
|
|
|
wg.Wait()
|
|
|
|
if len(failedCmds.m) == 0 {
|
2016-12-13 18:28:39 +03:00
|
|
|
break
|
|
|
|
}
|
2018-09-11 13:09:16 +03:00
|
|
|
cmdsMap = failedCmds.m
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 11:11:01 +03:00
|
|
|
return cmdsFirstErr(cmds)
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2016-10-13 13:56:24 +03:00
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
func (c *ClusterClient) mapCmdsBySlot(ctx context.Context, cmds []Cmder) map[int][]Cmder {
|
2016-12-13 18:28:39 +03:00
|
|
|
cmdsMap := make(map[int][]Cmder)
|
|
|
|
for _, cmd := range cmds {
|
2022-07-14 13:43:42 +03:00
|
|
|
slot := c.cmdSlot(ctx, cmd)
|
2016-12-13 18:28:39 +03:00
|
|
|
cmdsMap[slot] = append(cmdsMap[slot], cmd)
|
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
return cmdsMap
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2016-10-13 13:56:24 +03:00
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
func (c *ClusterClient) processTxPipelineNode(
|
2020-02-14 15:30:07 +03:00
|
|
|
ctx context.Context, node *clusterNode, cmds []Cmder, failedCmds *cmdsMap,
|
2022-10-06 14:05:55 +03:00
|
|
|
) {
|
2022-10-11 15:37:34 +03:00
|
|
|
cmds = wrapMultiExec(ctx, cmds)
|
2023-01-21 11:30:02 +03:00
|
|
|
_ = node.Client.withProcessPipelineHook(ctx, cmds, func(ctx context.Context, cmds []Cmder) error {
|
2022-11-21 12:55:19 +03:00
|
|
|
cn, err := node.Client.getConn(ctx)
|
|
|
|
if err != nil {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
|
|
|
setCmdsErr(cmds, err)
|
|
|
|
return err
|
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
|
2023-01-28 10:44:06 +03:00
|
|
|
var processErr error
|
|
|
|
defer func() {
|
|
|
|
node.Client.releaseConn(ctx, cn, processErr)
|
|
|
|
}()
|
|
|
|
processErr = c.processTxPipelineNodeConn(ctx, node, cn, cmds, failedCmds)
|
|
|
|
|
|
|
|
return processErr
|
2022-11-21 12:55:19 +03:00
|
|
|
})
|
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
func (c *ClusterClient) processTxPipelineNodeConn(
|
|
|
|
ctx context.Context, node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds *cmdsMap,
|
|
|
|
) error {
|
|
|
|
if err := cn.WithWriter(c.context(ctx), c.opt.WriteTimeout, func(wr *proto.Writer) error {
|
|
|
|
return writeCmds(wr, cmds)
|
|
|
|
}); err != nil {
|
|
|
|
if shouldRetry(err, true) {
|
|
|
|
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
|
|
|
|
}
|
|
|
|
setCmdsErr(cmds, err)
|
|
|
|
return err
|
|
|
|
}
|
2022-10-06 14:05:55 +03:00
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
return cn.WithReader(c.context(ctx), c.opt.ReadTimeout, func(rd *proto.Reader) error {
|
|
|
|
statusCmd := cmds[0].(*StatusCmd)
|
|
|
|
// Trim multi and exec.
|
|
|
|
trimmedCmds := cmds[1 : len(cmds)-1]
|
2022-10-06 14:05:55 +03:00
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
if err := c.txPipelineReadQueued(
|
|
|
|
ctx, rd, statusCmd, trimmedCmds, failedCmds,
|
|
|
|
); err != nil {
|
|
|
|
setCmdsErr(cmds, err)
|
2022-10-11 15:37:34 +03:00
|
|
|
|
2022-11-21 12:55:19 +03:00
|
|
|
moved, ask, addr := isMovedError(err)
|
|
|
|
if moved || ask {
|
|
|
|
return c.cmdsMoved(ctx, trimmedCmds, moved, ask, addr, failedCmds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipelineReadCmds(rd, trimmedCmds)
|
2022-10-11 15:37:34 +03:00
|
|
|
})
|
2020-02-14 15:30:07 +03:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
func (c *ClusterClient) txPipelineReadQueued(
|
2020-03-11 17:26:42 +03:00
|
|
|
ctx context.Context,
|
|
|
|
rd *proto.Reader,
|
|
|
|
statusCmd *StatusCmd,
|
|
|
|
cmds []Cmder,
|
|
|
|
failedCmds *cmdsMap,
|
2016-12-13 18:28:39 +03:00
|
|
|
) error {
|
|
|
|
// Parse queued replies.
|
2018-08-15 09:38:58 +03:00
|
|
|
if err := statusCmd.readReply(rd); err != nil {
|
2017-08-31 15:22:47 +03:00
|
|
|
return err
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range cmds {
|
2018-08-15 09:38:58 +03:00
|
|
|
err := statusCmd.readReply(rd)
|
2020-03-11 17:26:42 +03:00
|
|
|
if err == nil || c.checkMovedErr(ctx, cmd, err, failedCmds) || isRedisError(err) {
|
2017-08-31 15:22:47 +03:00
|
|
|
continue
|
2016-12-13 18:28:39 +03:00
|
|
|
}
|
2017-08-31 15:22:47 +03:00
|
|
|
return err
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:28:39 +03:00
|
|
|
// Parse number of replies.
|
2018-08-15 09:38:58 +03:00
|
|
|
line, err := rd.ReadLine()
|
2016-12-13 18:28:39 +03:00
|
|
|
if err != nil {
|
|
|
|
if err == Nil {
|
|
|
|
err = TxFailedErr
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:04:46 +03:00
|
|
|
if line[0] != proto.RespArray {
|
2019-08-08 16:54:38 +03:00
|
|
|
return fmt.Errorf("redis: expected '*', but got line %q", line)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClusterClient) cmdsMoved(
|
2020-03-11 17:26:42 +03:00
|
|
|
ctx context.Context, cmds []Cmder,
|
|
|
|
moved, ask bool,
|
|
|
|
addr string,
|
|
|
|
failedCmds *cmdsMap,
|
2019-08-08 16:54:38 +03:00
|
|
|
) error {
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err := c.nodes.GetOrCreate(addr)
|
2019-08-08 16:54:38 +03:00
|
|
|
if err != nil {
|
2016-12-13 18:28:39 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:54:38 +03:00
|
|
|
if moved {
|
2021-03-05 14:53:15 +03:00
|
|
|
c.state.LazyReload()
|
2019-08-08 16:54:38 +03:00
|
|
|
for _, cmd := range cmds {
|
|
|
|
failedCmds.Add(node, cmd)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if ask {
|
|
|
|
for _, cmd := range cmds {
|
2020-03-11 17:26:42 +03:00
|
|
|
failedCmds.Add(node, NewCmd(ctx, "asking"), cmd)
|
2019-08-08 16:54:38 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-31 15:22:47 +03:00
|
|
|
return nil
|
2016-04-09 10:47:15 +03:00
|
|
|
}
|
2017-06-30 00:43:19 +03:00
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error {
|
2019-05-31 16:36:57 +03:00
|
|
|
if len(keys) == 0 {
|
|
|
|
return fmt.Errorf("redis: Watch requires at least one key")
|
|
|
|
}
|
|
|
|
|
|
|
|
slot := hashtag.Slot(keys[0])
|
|
|
|
for _, key := range keys[1:] {
|
|
|
|
if hashtag.Slot(key) != slot {
|
|
|
|
err := fmt.Errorf("redis: Watch requires all keys to be in the same slot")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
node, err := c.slotMasterNode(ctx, slot)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
|
|
|
|
if attempt > 0 {
|
2019-07-30 12:13:00 +03:00
|
|
|
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
err = node.Client.Watch(ctx, fn, keys...)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-08-03 17:21:12 +03:00
|
|
|
moved, ask, addr := isMovedError(err)
|
2019-05-31 16:36:57 +03:00
|
|
|
if moved || ask {
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err = c.nodes.GetOrCreate(addr)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-30 11:13:15 +03:00
|
|
|
if isReadOnly := isReadOnlyError(err); isReadOnly || err == pool.ErrClosed {
|
|
|
|
if isReadOnly {
|
2021-03-05 14:53:15 +03:00
|
|
|
c.state.LazyReload()
|
2020-06-30 11:13:15 +03:00
|
|
|
}
|
2020-03-11 17:26:42 +03:00
|
|
|
node, err = c.slotMasterNode(ctx, slot)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-07-24 14:57:12 +03:00
|
|
|
if shouldRetry(err, true) {
|
2019-05-31 16:36:57 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:38:53 +03:00
|
|
|
func (c *ClusterClient) pubSub() *PubSub {
|
2017-07-09 10:07:20 +03:00
|
|
|
var node *clusterNode
|
2018-07-23 15:55:13 +03:00
|
|
|
pubsub := &PubSub{
|
|
|
|
opt: c.opt.clientOptions(),
|
2017-07-09 10:07:20 +03:00
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
newConn: func(ctx context.Context, channels []string) (*pool.Conn, error) {
|
2019-01-21 17:38:53 +03:00
|
|
|
if node != nil {
|
|
|
|
panic("node != nil")
|
|
|
|
}
|
2017-07-09 10:07:20 +03:00
|
|
|
|
2019-01-21 17:38:53 +03:00
|
|
|
var err error
|
2019-03-07 13:19:03 +03:00
|
|
|
if len(channels) > 0 {
|
|
|
|
slot := hashtag.Slot(channels[0])
|
2020-03-11 17:26:42 +03:00
|
|
|
node, err = c.slotMasterNode(ctx, slot)
|
2019-03-07 13:19:03 +03:00
|
|
|
} else {
|
|
|
|
node, err = c.nodes.Random()
|
|
|
|
}
|
2019-01-21 17:38:53 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-07-09 10:07:20 +03:00
|
|
|
}
|
2019-01-21 17:38:53 +03:00
|
|
|
|
2019-06-14 16:00:03 +03:00
|
|
|
cn, err := node.Client.newConn(context.TODO())
|
2019-01-21 17:38:53 +03:00
|
|
|
if err != nil {
|
2019-04-18 19:06:16 +03:00
|
|
|
node = nil
|
|
|
|
|
2019-01-21 17:38:53 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cn, nil
|
2017-07-09 10:07:20 +03:00
|
|
|
},
|
|
|
|
closeConn: func(cn *pool.Conn) error {
|
2019-01-21 17:38:53 +03:00
|
|
|
err := node.Client.connPool.CloseConn(cn)
|
|
|
|
node = nil
|
|
|
|
return err
|
2017-07-09 10:07:20 +03:00
|
|
|
},
|
|
|
|
}
|
2018-07-23 15:55:13 +03:00
|
|
|
pubsub.init()
|
2019-01-21 17:38:53 +03:00
|
|
|
|
2018-07-23 15:55:13 +03:00
|
|
|
return pubsub
|
2017-07-09 10:07:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Subscribe subscribes the client to the specified channels.
|
|
|
|
// Channels can be omitted to create empty subscription.
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) Subscribe(ctx context.Context, channels ...string) *PubSub {
|
2019-01-21 17:38:53 +03:00
|
|
|
pubsub := c.pubSub()
|
2017-07-09 10:07:20 +03:00
|
|
|
if len(channels) > 0 {
|
2020-03-11 17:26:42 +03:00
|
|
|
_ = pubsub.Subscribe(ctx, channels...)
|
2017-07-09 10:07:20 +03:00
|
|
|
}
|
|
|
|
return pubsub
|
|
|
|
}
|
|
|
|
|
|
|
|
// PSubscribe subscribes the client to the given patterns.
|
|
|
|
// Patterns can be omitted to create empty subscription.
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) PSubscribe(ctx context.Context, channels ...string) *PubSub {
|
2019-01-21 17:38:53 +03:00
|
|
|
pubsub := c.pubSub()
|
2017-07-09 10:07:20 +03:00
|
|
|
if len(channels) > 0 {
|
2020-03-11 17:26:42 +03:00
|
|
|
_ = pubsub.PSubscribe(ctx, channels...)
|
2017-07-09 10:07:20 +03:00
|
|
|
}
|
|
|
|
return pubsub
|
|
|
|
}
|
|
|
|
|
2022-08-03 18:10:03 +03:00
|
|
|
// SSubscribe Subscribes the client to the specified shard channels.
|
|
|
|
func (c *ClusterClient) SSubscribe(ctx context.Context, channels ...string) *PubSub {
|
|
|
|
pubsub := c.pubSub()
|
|
|
|
if len(channels) > 0 {
|
|
|
|
_ = pubsub.SSubscribe(ctx, channels...)
|
|
|
|
}
|
|
|
|
return pubsub
|
|
|
|
}
|
|
|
|
|
2019-05-31 16:36:57 +03:00
|
|
|
func (c *ClusterClient) retryBackoff(attempt int) time.Duration {
|
|
|
|
return internal.RetryBackoff(attempt, c.opt.MinRetryBackoff, c.opt.MaxRetryBackoff)
|
|
|
|
}
|
|
|
|
|
2020-09-14 15:30:50 +03:00
|
|
|
func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, error) {
|
2020-07-19 09:49:00 +03:00
|
|
|
// Try 3 random nodes.
|
|
|
|
const nodeLimit = 3
|
|
|
|
|
2019-05-31 16:36:57 +03:00
|
|
|
addrs, err := c.nodes.Addrs()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var firstErr error
|
2020-07-19 09:49:00 +03:00
|
|
|
|
|
|
|
perm := rand.Perm(len(addrs))
|
|
|
|
if len(perm) > nodeLimit {
|
|
|
|
perm = perm[:nodeLimit]
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, idx := range perm {
|
|
|
|
addr := addrs[idx]
|
|
|
|
|
chore: sync master (#2051)
* Upgrade redis-server version (#1833)
* Upgrade redis-server version
Signed-off-by: monkey <golang@88.com>
* XAutoClaim changed the return value
Signed-off-by: monkey <golang@88.com>
* add cmd: geosearch, geosearchstore (#1836)
* add cmd: geosearch, geosearchstore
Signed-off-by: monkey92t <golang@88.com>
* GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing
Signed-off-by: monkey92t <golang@88.com>
* Added missing method XInfoStreamFull to Cmdable interface
* Run go mod tidy in redisotel
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
* Revert "ConnPool check fd for bad conns (#1824)" (#1849)
This reverts commit 346bfafddd36dd52d51b064033048de5552ee91e.
* Automate release process (#1852)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0 (#1832)
* Bump github.com/onsi/gomega from 1.10.5 to 1.14.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.10.5 to 1.14.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.10.5...v1.14.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Upgrade gomega to v1.15.0
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: monkey92t <golang@88.com>
* Add version.go
* Fix otel example
* Fix package name in release script
* More fixes for otel example
* And more
* Fix release.sh
* Release v8.11.3 (release.sh)
* Create an annotated tag to give release.yml chance to run
* Tweak tag.sh
* Add Cmd.Slice helper to cast to []interface{} (#1859)
* after the connection pool is closed, no new connections should be added (#1863)
* after the connection pool is closed, no new connections should be added
Signed-off-by: monkey92t <golang@88.com>
* remove runGoroutine
Signed-off-by: monkey92t <golang@88.com>
* pool.popIdle add p.closed check
Signed-off-by: monkey92t <golang@88.com>
* upgrade golangci-lint v1.42.0
Signed-off-by: monkey92t <golang@88.com>
* Bump github.com/onsi/gomega from 1.15.0 to 1.16.0 (#1865)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.15.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add go 1.17 to the build matrix
* Remove go 1.15 from build matrix
* Add scan struct example (#1870)
* Replace release job
* Bump github.com/cespare/xxhash/v2 from 2.1.1 to 2.1.2 (#1872)
Bumps [github.com/cespare/xxhash/v2](https://github.com/cespare/xxhash) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/cespare/xxhash/releases)
- [Commits](https://github.com/cespare/xxhash/compare/v2.1.1...v2.1.2)
---
updated-dependencies:
- dependency-name: github.com/cespare/xxhash/v2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix tag script to push tag by tag
* Fix releasing.md
* Fix/pubsub ping mutex (#1878)
* Fix PubSub.Ping to hold the lock
* Fix PubSub.Ping to hold the lock
* add write cmd data-race test
Signed-off-by: monkey92t <golang@88.com>
Co-authored-by: monkey92t <golang@88.com>
* chore: cleanup OpenTelemetry example
* chore: gofmt all code
* Refactor TestParseURL
This is in preparation for supporting query parameters
in ParseURL:
- use an expected *Options instance to execute assertions on
- extract assertions into helper function
- enable parallel testing
- condense test table
* Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted
set of URLs (it returned an error, if it encountered any parameter).
This commit introduces the ability to process URLs like
redis://localhost/1?dial_timeout=10s
and similar.
Go programs which were providing a configuration tunable (e.g.
CLI flag, config entry or environment variable) to configure
the Redis connection now don't need to perform this task
themselves.
* chore: add links to readme
* chore: fix discussions link
* empty hooks.withContext removed
* chore: gofmt
* chore: use conventional commits and auto-generate changelog
* feat: add acl auth support for sentinels
* chore: swap to acl auth at the test-level
* Add support for BLMove command
* chore: update dependencies
* chore: update link
* feat: add SetVal method for each command
* feat: add Cmd.{String,Int,Float,Bool}Slice helpers and an example
* chore: tweak GH actions to run all jobs
* chore: add Lua scripting example
* Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios
This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.
The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
* chore: lazy reload when moved or ask
* chore: use conv commit message
* chore: release v8.11.4 (release.sh)
* fix: add whitespace for avoid unlikely colisions
* fix: format
* chore: fix links
* chore: use ctx parameter in cmdInfo
* Bump github.com/onsi/ginkgo from 1.16.4 to 1.16.5 (#1925)
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.16.4 to 1.16.5.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v1.16.4...v1.16.5)
---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add support for time.Duration write and scan
* test: add test case for setting and scanning durations
* chore: fix linter
* fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client
libraries.
I've also removed the SetAttributes call and instead set the attributes during creation of the span.
This is what the library SHOULD be doing according to the opentelemetry api specification.
* chore: update otel example
* fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in
argument array is missing 1 or 2 elements,
which results in re-allocation of twice as large array
* chore: add example how to delete keys without a ttl
* chore: don't enable all lints
* chore(deps): bump github.com/onsi/gomega from 1.16.0 to 1.17.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.16.0...v1.17.0)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* feat: Add redis v7's NX, XX, GT, LT expire variants
* chore: add missing readme
* chore: tweak feature links
* chore: remove Discord
* fix: set timeout for WAIT command. Fixes #1963
* build: update `go` directive in `go.mod` to 1.17
This commit enables support for module graph pruning and lazy module
loading for projects that are at Go 1.17 or higher.
Reference: https://go.dev/ref/mod#go-mod-file-go
Reference: https://go.dev/ref/mod#graph-pruning
Reference: https://go.dev/ref/mod#lazy-loading
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* chore: update link
* chore: export cmder.SetFirstKeyPos to support build module commands
* feat(redisotel): ability to override TracerProvider (#1998)
* fix: add missing Expire methods to Cmdable
This is a followup to https://github.com/go-redis/redis/pull/1928
* chore(deps): bump github.com/onsi/gomega from 1.17.0 to 1.18.1
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.18.1)
---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Update README.md (#2011)
chore: add fmt library in example code
* chore: instrumentation name and version (#2012)
* fix: invalid type assert in stringArg
* chore: cleanup
* fix: example/otel compile error (#2028)
* fix: rename Golang to Go (#2030)
https://go.dev/doc/faq#go_or_golang
* feat: add support for passing extra attributes added to spans
* feat: set net.peer.name and net.peer.port in otel example
* chore: tweak Uptrace copy
* feat: add support for COPY command (#2016)
* feat: add support for acl sentinel auth in universal client
* chore(deps): bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: add hll example
* chore: tweak release script
* chore: release v8.11.5 (release.sh)
* chore: add discord back
Co-authored-by: Eugene Ponizovsky <ponizovsky@gmail.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kishan B <kishancs46@gmail.com>
Co-authored-by: Dominik Menke <dom@digineo.de>
Co-authored-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
Co-authored-by: Justin Sievenpiper <justin@sievenpiper.co>
Co-authored-by: Алексей Романовский <aromanovsky@epiphan.com>
Co-authored-by: Stavros Panakakakis <stavrospanakakis@gmail.com>
Co-authored-by: Pau Freixes <pfreixes@gmail.com>
Co-authored-by: Ethan Hur <ethan0311@gmail.com>
Co-authored-by: Jackie <18378976+Pyrodash@users.noreply.github.com>
Co-authored-by: Kristinn Björgvin Árdal <kristinnardalsecondary@gmail.com>
Co-authored-by: ffenix113 <razerer@bigmir.net>
Co-authored-by: Bastien Penavayre <bastienPenava@gmail.com>
Co-authored-by: James3 Li(李麒傑) <james3_li@asus.com>
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: gzjiangtao2014 <gzjiangtao2014@corp.netease.com>
Co-authored-by: Nelz <nelz9999@users.noreply.github.com>
Co-authored-by: Daniel Richter <Nexyz9@gmail.com>
Co-authored-by: Seyed Ali Ghaffari <ali.ghaffari@outlook.com>
Co-authored-by: lintanghui <lintanghui@bilibili.com>
Co-authored-by: hidu <duv123+github@gmail.com>
Co-authored-by: Jonas Lergell <jonas.lergell@volvocars.com>
Co-authored-by: Alex Kahn <alexanderkahn@gmail.com>
2022-03-19 07:40:31 +03:00
|
|
|
node, err := c.nodes.GetOrCreate(addr)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
2020-07-19 09:49:00 +03:00
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
2019-05-31 16:36:57 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-09-14 15:30:50 +03:00
|
|
|
info, err := node.Client.Command(ctx).Result()
|
2019-05-31 16:36:57 +03:00
|
|
|
if err == nil {
|
|
|
|
return info, nil
|
|
|
|
}
|
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
}
|
2020-07-19 09:49:00 +03:00
|
|
|
|
|
|
|
if firstErr == nil {
|
|
|
|
panic("not reached")
|
|
|
|
}
|
2019-05-31 16:36:57 +03:00
|
|
|
return nil, firstErr
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
|
|
|
|
cmdsInfo, err := c.cmdsInfoCache.Get(ctx)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
2022-07-07 00:28:42 +03:00
|
|
|
internal.Logger.Printf(context.TODO(), "getting command info: %s", err)
|
2019-05-31 16:36:57 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
info := cmdsInfo[name]
|
|
|
|
if info == nil {
|
2022-06-05 09:58:05 +03:00
|
|
|
internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name)
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
func (c *ClusterClient) cmdSlot(ctx context.Context, cmd Cmder) int {
|
2019-05-31 16:36:57 +03:00
|
|
|
args := cmd.Args()
|
|
|
|
if args[0] == "cluster" && args[1] == "getkeysinslot" {
|
|
|
|
return args[2].(int)
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:43:42 +03:00
|
|
|
cmdInfo := c.cmdInfo(ctx, cmd.Name())
|
2019-05-31 16:36:57 +03:00
|
|
|
return cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo))
|
|
|
|
}
|
|
|
|
|
2019-06-16 13:58:15 +03:00
|
|
|
func cmdSlot(cmd Cmder, pos int) int {
|
|
|
|
if pos == 0 {
|
|
|
|
return hashtag.RandomSlot()
|
|
|
|
}
|
|
|
|
firstKey := cmd.stringArg(pos)
|
|
|
|
return hashtag.Slot(firstKey)
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) cmdNode(
|
|
|
|
ctx context.Context,
|
|
|
|
cmdInfo *CommandInfo,
|
|
|
|
slot int,
|
|
|
|
) (*clusterNode, error) {
|
|
|
|
state, err := c.state.Get(ctx)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
2019-06-16 13:58:15 +03:00
|
|
|
return nil, err
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 10:33:09 +03:00
|
|
|
if c.opt.ReadOnly && cmdInfo != nil && cmdInfo.ReadOnly {
|
2020-02-02 14:01:57 +03:00
|
|
|
return c.slotReadOnlyNode(state, slot)
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
2019-06-16 13:58:15 +03:00
|
|
|
return state.slotMasterNode(slot)
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 15:37:34 +03:00
|
|
|
func (c *ClusterClient) slotReadOnlyNode(state *clusterState, slot int) (*clusterNode, error) {
|
2020-02-02 14:01:57 +03:00
|
|
|
if c.opt.RouteByLatency {
|
|
|
|
return state.slotClosestNode(slot)
|
|
|
|
}
|
|
|
|
if c.opt.RouteRandomly {
|
|
|
|
return state.slotRandomNode(slot)
|
|
|
|
}
|
|
|
|
return state.slotSlaveNode(slot)
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:26:42 +03:00
|
|
|
func (c *ClusterClient) slotMasterNode(ctx context.Context, slot int) (*clusterNode, error) {
|
|
|
|
state, err := c.state.Get(ctx)
|
2019-05-31 16:36:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-02 14:01:57 +03:00
|
|
|
return state.slotMasterNode(slot)
|
2019-05-31 16:36:57 +03:00
|
|
|
}
|
|
|
|
|
2020-12-16 18:45:06 +03:00
|
|
|
// SlaveForKey gets a client for a replica node to run any command on it.
|
2020-12-16 14:25:40 +03:00
|
|
|
// This is especially useful if we want to run a particular lua script which has
|
|
|
|
// only read only commands on the replica.
|
|
|
|
// This is because other redis commands generally have a flag that points that
|
|
|
|
// they are read only and automatically run on the replica nodes
|
|
|
|
// if ClusterOptions.ReadOnly flag is set to true.
|
2020-12-16 18:45:06 +03:00
|
|
|
func (c *ClusterClient) SlaveForKey(ctx context.Context, key string) (*Client, error) {
|
2020-12-16 14:25:40 +03:00
|
|
|
state, err := c.state.Get(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
slot := hashtag.Slot(key)
|
|
|
|
node, err := c.slotReadOnlyNode(state, slot)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return node.Client, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// MasterForKey return a client to the master node for a particular key.
|
|
|
|
func (c *ClusterClient) MasterForKey(ctx context.Context, key string) (*Client, error) {
|
|
|
|
slot := hashtag.Slot(key)
|
|
|
|
node, err := c.slotMasterNode(ctx, slot)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return node.Client, err
|
|
|
|
}
|
|
|
|
|
2022-10-11 10:22:42 +03:00
|
|
|
func (c *ClusterClient) context(ctx context.Context) context.Context {
|
|
|
|
if c.opt.ContextTimeoutEnabled {
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
return context.Background()
|
|
|
|
}
|
|
|
|
|
2018-05-17 16:09:56 +03:00
|
|
|
func appendUniqueNode(nodes []*clusterNode, node *clusterNode) []*clusterNode {
|
2017-07-09 13:10:07 +03:00
|
|
|
for _, n := range nodes {
|
|
|
|
if n == node {
|
|
|
|
return nodes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return append(nodes, node)
|
|
|
|
}
|
2018-03-14 13:42:51 +03:00
|
|
|
|
|
|
|
func appendIfNotExists(ss []string, es ...string) []string {
|
|
|
|
loop:
|
|
|
|
for _, e := range es {
|
|
|
|
for _, s := range ss {
|
|
|
|
if s == e {
|
|
|
|
continue loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ss = append(ss, e)
|
|
|
|
}
|
|
|
|
return ss
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:01:57 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type cmdsMap struct {
|
|
|
|
mu sync.Mutex
|
|
|
|
m map[*clusterNode][]Cmder
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCmdsMap() *cmdsMap {
|
|
|
|
return &cmdsMap{
|
|
|
|
m: make(map[*clusterNode][]Cmder),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *cmdsMap) Add(node *clusterNode, cmds ...Cmder) {
|
|
|
|
m.mu.Lock()
|
|
|
|
m.m[node] = append(m.m[node], cmds...)
|
|
|
|
m.mu.Unlock()
|
|
|
|
}
|