Update module go-redis/redis/v7 to v7.3.0 (#565)

Update module go-redis/redis/v7 to v7.3.0

Reviewed-on: vikunja/api#565
This commit is contained in:
renovate 2020-05-21 08:56:39 +00:00 committed by konrad
parent cc47d11792
commit b0948a37d4
20 changed files with 96 additions and 12 deletions

2
go.mod
View File

@ -33,7 +33,7 @@ require (
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835
github.com/go-openapi/jsonreference v0.19.3 // indirect github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.4 // indirect github.com/go-openapi/spec v0.19.4 // indirect
github.com/go-redis/redis/v7 v7.2.0 github.com/go-redis/redis/v7 v7.3.0
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/go-testfixtures/testfixtures/v3 v3.2.0 github.com/go-testfixtures/testfixtures/v3 v3.2.0
github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf

2
go.sum
View File

@ -153,6 +153,8 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs= github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs=
github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-redis/redis/v7 v7.3.0 h1:3oHqd0W7f/VLKBxeYTEpqdMUsmMectngjM9OtoRoIgg=
github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=

View File

@ -1,5 +1,4 @@
dist: xenial dist: xenial
sudo: false
language: go language: go
services: services:

View File

@ -4,6 +4,10 @@
- Existing `HMSet` is renamed to `HSet` and old deprecated `HMSet` is restored for Redis 3 users. - Existing `HMSet` is renamed to `HSet` and old deprecated `HMSet` is restored for Redis 3 users.
## v7.1
- Existing `Cmd.String` is renamed to `Cmd.Text`. New `Cmd.String` implements `fmt.Stringer` interface.
## v7 ## v7
- *Important*. Tx.Pipeline now returns a non-transactional pipeline. Use Tx.TxPipeline for a transactional pipeline. - *Important*. Tx.Pipeline now returns a non-transactional pipeline. Use Tx.TxPipeline for a transactional pipeline.

View File

@ -101,7 +101,7 @@ set, err := client.SetNX("key", "value", 10*time.Second).Result()
vals, err := client.Sort("list", &redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result() vals, err := client.Sort("list", &redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
// ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2 // ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{ vals, err := client.ZRangeByScoreWithScores("zset", &redis.ZRangeBy{
Min: "-inf", Min: "-inf",
Max: "+inf", Max: "+inf",
Offset: 0, Offset: 0,
@ -109,7 +109,10 @@ vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
}).Result() }).Result()
// ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM // ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM
vals, err := client.ZInterStore("out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2").Result() vals, err := client.ZInterStore("out", &redis.ZStore{
Keys: []string{"zset1", "zset2"},
Weights: []int64{2, 3}
}).Result()
// EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello" // EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello"
vals, err := client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, "hello").Result() vals, err := client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, "hello").Result()

View File

@ -57,6 +57,7 @@ type ClusterOptions struct {
OnConnect func(*Conn) error OnConnect func(*Conn) error
Username string
Password string Password string
MaxRetries int MaxRetries int
@ -67,6 +68,9 @@ type ClusterOptions struct {
ReadTimeout time.Duration ReadTimeout time.Duration
WriteTimeout time.Duration WriteTimeout time.Duration
// NewClient creates a cluster node client with provided name and options.
NewClient func(opt *Options) *Client
// PoolSize applies per cluster node and not for the whole cluster. // PoolSize applies per cluster node and not for the whole cluster.
PoolSize int PoolSize int
MinIdleConns int MinIdleConns int
@ -118,6 +122,10 @@ func (opt *ClusterOptions) init() {
case 0: case 0:
opt.MaxRetryBackoff = 512 * time.Millisecond opt.MaxRetryBackoff = 512 * time.Millisecond
} }
if opt.NewClient == nil {
opt.NewClient = NewClient
}
} }
func (opt *ClusterOptions) clientOptions() *Options { func (opt *ClusterOptions) clientOptions() *Options {
@ -130,6 +138,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
MaxRetries: opt.MaxRetries, MaxRetries: opt.MaxRetries,
MinRetryBackoff: opt.MinRetryBackoff, MinRetryBackoff: opt.MinRetryBackoff,
MaxRetryBackoff: opt.MaxRetryBackoff, MaxRetryBackoff: opt.MaxRetryBackoff,
Username: opt.Username,
Password: opt.Password, Password: opt.Password,
readOnly: opt.ReadOnly, readOnly: opt.ReadOnly,
@ -162,7 +171,7 @@ func newClusterNode(clOpt *ClusterOptions, addr string) *clusterNode {
opt := clOpt.clientOptions() opt := clOpt.clientOptions()
opt.Addr = addr opt.Addr = addr
node := clusterNode{ node := clusterNode{
Client: NewClient(opt), Client: clOpt.NewClient(opt),
} }
node.latency = math.MaxUint32 node.latency = math.MaxUint32

View File

@ -671,7 +671,7 @@ func (cmd *StringCmd) Time() (time.Time, error) {
if cmd.err != nil { if cmd.err != nil {
return time.Time{}, cmd.err return time.Time{}, cmd.err
} }
return time.Parse(time.RFC3339, cmd.Val()) return time.Parse(time.RFC3339Nano, cmd.Val())
} }
func (cmd *StringCmd) Scan(val interface{}) error { func (cmd *StringCmd) Scan(val interface{}) error {

View File

@ -302,6 +302,7 @@ type Cmdable interface {
type StatefulCmdable interface { type StatefulCmdable interface {
Cmdable Cmdable
Auth(password string) *StatusCmd Auth(password string) *StatusCmd
AuthACL(username, password string) *StatusCmd
Select(index int) *StatusCmd Select(index int) *StatusCmd
SwapDB(index1, index2 int) *StatusCmd SwapDB(index1, index2 int) *StatusCmd
ClientSetName(name string) *BoolCmd ClientSetName(name string) *BoolCmd
@ -324,6 +325,15 @@ func (c statefulCmdable) Auth(password string) *StatusCmd {
return cmd return cmd
} }
// Perform an AUTH command, using the given user and pass.
// Should be used to authenticate the current connection with one of the connections defined in the ACL list
// when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
func (c statefulCmdable) AuthACL(username, password string) *StatusCmd {
cmd := NewStatusCmd("auth", username, password)
_ = c(cmd)
return cmd
}
func (c cmdable) Echo(message interface{}) *StringCmd { func (c cmdable) Echo(message interface{}) *StringCmd {
cmd := NewStringCmd("echo", message) cmd := NewStringCmd("echo", message)
_ = c(cmd) _ = c(cmd)

View File

@ -6,9 +6,24 @@ import (
"net" "net"
"strings" "strings"
"github.com/go-redis/redis/v7/internal/pool"
"github.com/go-redis/redis/v7/internal/proto" "github.com/go-redis/redis/v7/internal/proto"
) )
var ErrClosed = pool.ErrClosed
type Error interface {
error
// RedisError is a no-op function but
// serves to distinguish types that are Redis
// errors from ordinary errors: a type is a
// Redis error if it has a RedisError method.
RedisError()
}
var _ Error = proto.RedisError("")
func isRetryableError(err error, retryTimeout bool) bool { func isRetryableError(err error, retryTimeout bool) bool {
switch err { switch err {
case nil, context.Canceled, context.DeadlineExceeded: case nil, context.Canceled, context.DeadlineExceeded:

View File

@ -94,7 +94,9 @@ func NewConnPool(opt *Options) *ConnPool {
closedCh: make(chan struct{}), closedCh: make(chan struct{}),
} }
p.connsMu.Lock()
p.checkMinIdleConns() p.checkMinIdleConns()
p.connsMu.Unlock()
if opt.IdleTimeout > 0 && opt.IdleCheckFrequency > 0 { if opt.IdleTimeout > 0 && opt.IdleCheckFrequency > 0 {
go p.reaper(opt.IdleCheckFrequency) go p.reaper(opt.IdleCheckFrequency)

View File

@ -24,6 +24,8 @@ type RedisError string
func (e RedisError) Error() string { return string(e) } func (e RedisError) Error() string { return string(e) }
func (RedisError) RedisError() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
type MultiBulkParse func(*Reader, int64) (interface{}, error) type MultiBulkParse func(*Reader, int64) (interface{}, error)

View File

@ -93,7 +93,7 @@ func (w *Writer) writeArg(v interface{}) error {
} }
return w.int(0) return w.int(0)
case time.Time: case time.Time:
return w.string(v.Format(time.RFC3339)) return w.string(v.Format(time.RFC3339Nano))
case encoding.BinaryMarshaler: case encoding.BinaryMarshaler:
b, err := v.MarshalBinary() b, err := v.MarshalBinary()
if err != nil { if err != nil {

View File

@ -40,8 +40,13 @@ type Options struct {
// Hook that is called when new connection is established. // Hook that is called when new connection is established.
OnConnect func(*Conn) error OnConnect func(*Conn) error
// Use the specified Username to authenticate the current connection with one of the connections defined in the ACL
// list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
Username string
// Optional password. Must match the password specified in the // Optional password. Must match the password specified in the
// requirepass server configuration option. // requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
// or the User Password when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
Password string Password string
// Database to be selected after connecting to the server. // Database to be selected after connecting to the server.
DB int DB int
@ -187,6 +192,7 @@ func ParseURL(redisURL string) (*Options, error) {
} }
if u.User != nil { if u.User != nil {
o.Username = u.User.Username()
if p, ok := u.User.Password(); ok { if p, ok := u.User.Password(); ok {
o.Password = p o.Password = p
} }

View File

@ -309,9 +309,11 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
case []interface{}: case []interface{}:
switch kind := reply[0].(string); kind { switch kind := reply[0].(string); kind {
case "subscribe", "unsubscribe", "psubscribe", "punsubscribe": case "subscribe", "unsubscribe", "psubscribe", "punsubscribe":
// Can be nil in case of "unsubscribe".
channel, _ := reply[1].(string)
return &Subscription{ return &Subscription{
Kind: kind, Kind: kind,
Channel: reply[1].(string), Channel: channel,
Count: int(reply[2].(int64)), Count: int(reply[2].(int64)),
}, nil }, nil
case "message": case "message":

View File

@ -241,7 +241,11 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
_, err := conn.Pipelined(func(pipe Pipeliner) error { _, err := conn.Pipelined(func(pipe Pipeliner) error {
if c.opt.Password != "" { if c.opt.Password != "" {
pipe.Auth(c.opt.Password) if c.opt.Username != "" {
pipe.AuthACL(c.opt.Username, c.opt.Password)
} else {
pipe.Auth(c.opt.Password)
}
} }
if c.opt.DB > 0 { if c.opt.DB > 0 {

View File

@ -98,6 +98,14 @@ func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd
return &cmd return &cmd
} }
// NewTimeCmdResult returns a TimeCmd initialised with val and err for testing
func NewTimeCmdResult(val time.Time, err error) *TimeCmd {
var cmd TimeCmd
cmd.val = val
cmd.SetErr(err)
return &cmd
}
// NewZSliceCmdResult returns a ZSliceCmd initialised with val and err for testing // NewZSliceCmdResult returns a ZSliceCmd initialised with val and err for testing
func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd { func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
var cmd ZSliceCmd var cmd ZSliceCmd

View File

@ -56,6 +56,9 @@ type RingOptions struct {
// See https://arxiv.org/abs/1406.2294 for reference // See https://arxiv.org/abs/1406.2294 for reference
HashReplicas int HashReplicas int
// NewClient creates a shard client with provided name and options.
NewClient func(name string, opt *Options) *Client
// Optional hook that is called when a new shard is created. // Optional hook that is called when a new shard is created.
OnNewShard func(*Client) OnNewShard func(*Client)
@ -390,7 +393,12 @@ func NewRing(opt *RingOptions) *Ring {
func newRingShard(opt *RingOptions, name, addr string) *Client { func newRingShard(opt *RingOptions, name, addr string) *Client {
clopt := opt.clientOptions(name) clopt := opt.clientOptions(name)
clopt.Addr = addr clopt.Addr = addr
shard := NewClient(clopt) var shard *Client
if opt.NewClient != nil {
shard = opt.NewClient(name, clopt)
} else {
shard = NewClient(clopt)
}
if opt.OnNewShard != nil { if opt.OnNewShard != nil {
opt.OnNewShard(shard) opt.OnNewShard(shard)
} }

View File

@ -22,6 +22,7 @@ type FailoverOptions struct {
MasterName string MasterName string
// A seed list of host:port addresses of sentinel nodes. // A seed list of host:port addresses of sentinel nodes.
SentinelAddrs []string SentinelAddrs []string
SentinelUsername string
SentinelPassword string SentinelPassword string
// Following options are copied from Options struct. // Following options are copied from Options struct.
@ -29,6 +30,7 @@ type FailoverOptions struct {
Dialer func(ctx context.Context, network, addr string) (net.Conn, error) Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
OnConnect func(*Conn) error OnConnect func(*Conn) error
Username string
Password string Password string
DB int DB int
@ -57,6 +59,7 @@ func (opt *FailoverOptions) options() *Options {
OnConnect: opt.OnConnect, OnConnect: opt.OnConnect,
DB: opt.DB, DB: opt.DB,
Username: opt.Username,
Password: opt.Password, Password: opt.Password,
MaxRetries: opt.MaxRetries, MaxRetries: opt.MaxRetries,
@ -88,6 +91,7 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
failover := &sentinelFailover{ failover := &sentinelFailover{
masterName: failoverOpt.MasterName, masterName: failoverOpt.MasterName,
sentinelAddrs: failoverOpt.SentinelAddrs, sentinelAddrs: failoverOpt.SentinelAddrs,
username: failoverOpt.SentinelUsername,
password: failoverOpt.SentinelPassword, password: failoverOpt.SentinelPassword,
opt: opt, opt: opt,
@ -281,6 +285,7 @@ type sentinelFailover struct {
sentinelAddrs []string sentinelAddrs []string
opt *Options opt *Options
username string
password string password string
pool *pool.ConnPool pool *pool.ConnPool
@ -372,6 +377,7 @@ func (c *sentinelFailover) masterAddr() (string, error) {
Addr: sentinelAddr, Addr: sentinelAddr,
Dialer: c.opt.Dialer, Dialer: c.opt.Dialer,
Username: c.username,
Password: c.password, Password: c.password,
MaxRetries: c.opt.MaxRetries, MaxRetries: c.opt.MaxRetries,

View File

@ -22,6 +22,7 @@ type UniversalOptions struct {
Dialer func(ctx context.Context, network, addr string) (net.Conn, error) Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
OnConnect func(*Conn) error OnConnect func(*Conn) error
Username string
Password string Password string
MaxRetries int MaxRetries int
MinRetryBackoff time.Duration MinRetryBackoff time.Duration
@ -60,6 +61,7 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
Dialer: o.Dialer, Dialer: o.Dialer,
OnConnect: o.OnConnect, OnConnect: o.OnConnect,
Username: o.Username,
Password: o.Password, Password: o.Password,
MaxRedirects: o.MaxRedirects, MaxRedirects: o.MaxRedirects,
@ -99,6 +101,7 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
OnConnect: o.OnConnect, OnConnect: o.OnConnect,
DB: o.DB, DB: o.DB,
Username: o.Username,
Password: o.Password, Password: o.Password,
MaxRetries: o.MaxRetries, MaxRetries: o.MaxRetries,
@ -133,6 +136,7 @@ func (o *UniversalOptions) Simple() *Options {
OnConnect: o.OnConnect, OnConnect: o.OnConnect,
DB: o.DB, DB: o.DB,
Username: o.Username,
Password: o.Password, Password: o.Password,
MaxRetries: o.MaxRetries, MaxRetries: o.MaxRetries,

2
vendor/modules.txt vendored
View File

@ -66,7 +66,7 @@ github.com/go-openapi/jsonreference
github.com/go-openapi/spec github.com/go-openapi/spec
# github.com/go-openapi/swag v0.19.5 # github.com/go-openapi/swag v0.19.5
github.com/go-openapi/swag github.com/go-openapi/swag
# github.com/go-redis/redis/v7 v7.2.0 # github.com/go-redis/redis/v7 v7.3.0
github.com/go-redis/redis/v7 github.com/go-redis/redis/v7
github.com/go-redis/redis/v7/internal github.com/go-redis/redis/v7/internal
github.com/go-redis/redis/v7/internal/consistenthash github.com/go-redis/redis/v7/internal/consistenthash