From 79a2bec76189a88cc6a71d750dd2581184f89c5b Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Sun, 20 Apr 2025 19:08:08 +0300 Subject: [PATCH 1/5] migrate golangci-lint config to v2 format --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 515750af6..06ad0a6c3 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -23,5 +23,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6.5.2 with: - verify: false # disable verifying the configuration since golangci is currently introducing breaking changes in the configuration + verify: true diff --git a/.golangci.yml b/.golangci.yml index 285aca6b3..dfd3f260a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,23 @@ +version: "2" run: timeout: 5m tests: false +linters: + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ From d3073d90f353d5ce3faa37c4ae7628d9605f92db Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Sun, 20 Apr 2025 19:23:11 +0300 Subject: [PATCH 2/5] chore: skip CI on migration [skip ci] From 2f4c38ba72e2cc481796e5ea02e7de84bea76e68 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 23 Apr 2025 23:00:33 +0300 Subject: [PATCH 3/5] Bump golangci version --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 06ad0a6c3..5e0ac1d0a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v6.5.2 + uses: golangci/golangci-lint-action@v7.0.0 with: verify: true From 72fabf54cb1ea230709415708d2a8d715e749c90 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 23 Apr 2025 23:18:13 +0300 Subject: [PATCH 4/5] Address several golangci-lint/staticcheck warnings --- command.go | 5 +++-- extra/rediscensus/go.mod | 2 +- extra/rediscmd/go.mod | 2 +- extra/redisotel/go.mod | 2 +- extra/redisprometheus/go.mod | 2 +- json.go | 4 ++-- options.go | 5 +++-- osscluster.go | 5 +++-- redis.go | 18 +++++++++--------- ring.go | 5 +++-- sentinel.go | 4 ++-- tx.go | 8 ++++---- 12 files changed, 33 insertions(+), 29 deletions(-) diff --git a/command.go b/command.go index 364706e3e..3253af6cc 100644 --- a/command.go +++ b/command.go @@ -1412,7 +1412,8 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { cmd.val = make(map[string][]interface{}) - if readType == proto.RespMap { + switch readType { + case proto.RespMap: n, err := rd.ReadMapLen() if err != nil { return err @@ -1435,7 +1436,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { cmd.val[k][j] = value } } - } else if readType == proto.RespArray { + case proto.RespArray: // RESP2 response n, err := rd.ReadArrayLen() if err != nil { diff --git a/extra/rediscensus/go.mod b/extra/rediscensus/go.mod index 7033e805f..b39f7dd4c 100644 --- a/extra/rediscensus/go.mod +++ b/extra/rediscensus/go.mod @@ -19,6 +19,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/rediscmd/go.mod b/extra/rediscmd/go.mod index c1cff3e90..93cc423db 100644 --- a/extra/rediscmd/go.mod +++ b/extra/rediscmd/go.mod @@ -16,6 +16,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/redisotel/go.mod b/extra/redisotel/go.mod index e5b442e61..c5b29dffa 100644 --- a/extra/redisotel/go.mod +++ b/extra/redisotel/go.mod @@ -24,6 +24,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/redisprometheus/go.mod b/extra/redisprometheus/go.mod index 8bff00086..c934767e0 100644 --- a/extra/redisprometheus/go.mod +++ b/extra/redisprometheus/go.mod @@ -23,6 +23,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/json.go b/json.go index b3cadf4b7..d4479c788 100644 --- a/json.go +++ b/json.go @@ -113,7 +113,7 @@ func (cmd *JSONCmd) Expanded() (interface{}, error) { func (cmd *JSONCmd) readReply(rd *proto.Reader) error { // nil response from JSON.(M)GET (cmd.baseCmd.err will be "redis: nil") - if cmd.baseCmd.Err() == Nil { + if cmd.Err() == Nil { cmd.val = "" return Nil } @@ -182,7 +182,7 @@ func (cmd *JSONSliceCmd) Result() ([]interface{}, error) { } func (cmd *JSONSliceCmd) readReply(rd *proto.Reader) error { - if cmd.baseCmd.Err() == Nil { + if cmd.Err() == Nil { cmd.val = nil return Nil } diff --git a/options.go b/options.go index 0ebeec342..3ffcd07ed 100644 --- a/options.go +++ b/options.go @@ -214,9 +214,10 @@ func (opt *Options) init() { opt.ConnMaxIdleTime = 30 * time.Minute } - if opt.MaxRetries == -1 { + switch opt.MaxRetries { + case -1: opt.MaxRetries = 0 - } else if opt.MaxRetries == 0 { + case 0: opt.MaxRetries = 3 } switch opt.MinRetryBackoff { diff --git a/osscluster.go b/osscluster.go index 20180464e..3b46cbe35 100644 --- a/osscluster.go +++ b/osscluster.go @@ -111,9 +111,10 @@ type ClusterOptions struct { } func (opt *ClusterOptions) init() { - if opt.MaxRedirects == -1 { + switch opt.MaxRedirects { + case -1: opt.MaxRedirects = 0 - } else if opt.MaxRedirects == 0 { + case 0: opt.MaxRedirects = 3 } diff --git a/redis.go b/redis.go index e0159294d..8521eed59 100644 --- a/redis.go +++ b/redis.go @@ -677,16 +677,16 @@ func NewClient(opt *Options) *Client { func (c *Client) init() { c.cmdable = c.Process c.initHooks(hooks{ - dial: c.baseClient.dial, - process: c.baseClient.process, - pipeline: c.baseClient.processPipeline, - txPipeline: c.baseClient.processTxPipeline, + dial: c.dial, + process: c.process, + pipeline: c.processPipeline, + txPipeline: c.processTxPipeline, }) } func (c *Client) WithTimeout(timeout time.Duration) *Client { clone := *c - clone.baseClient = c.baseClient.withTimeout(timeout) + clone.baseClient = c.withTimeout(timeout) clone.init() return &clone } @@ -839,10 +839,10 @@ func newConn(opt *Options, connPool pool.Pooler) *Conn { c.cmdable = c.Process c.statefulCmdable = c.Process c.initHooks(hooks{ - dial: c.baseClient.dial, - process: c.baseClient.process, - pipeline: c.baseClient.processPipeline, - txPipeline: c.baseClient.processTxPipeline, + dial: c.dial, + process: c.process, + pipeline: c.processPipeline, + txPipeline: c.processTxPipeline, }) return &c diff --git a/ring.go b/ring.go index 0ff3f75b1..8f2dd3c40 100644 --- a/ring.go +++ b/ring.go @@ -128,9 +128,10 @@ func (opt *RingOptions) init() { opt.NewConsistentHash = newRendezvous } - if opt.MaxRetries == -1 { + switch opt.MaxRetries { + case -1: opt.MaxRetries = 0 - } else if opt.MaxRetries == 0 { + case 0: opt.MaxRetries = 3 } switch opt.MinRetryBackoff { diff --git a/sentinel.go b/sentinel.go index f5b9a52d1..d679e451f 100644 --- a/sentinel.go +++ b/sentinel.go @@ -321,8 +321,8 @@ func NewSentinelClient(opt *Options) *SentinelClient { } c.initHooks(hooks{ - dial: c.baseClient.dial, - process: c.baseClient.process, + dial: c.dial, + process: c.process, }) c.connPool = newConnPool(opt, c.dialHook) diff --git a/tx.go b/tx.go index 039eaf351..552fe8db1 100644 --- a/tx.go +++ b/tx.go @@ -39,10 +39,10 @@ func (c *Tx) init() { c.statefulCmdable = c.Process c.initHooks(hooks{ - dial: c.baseClient.dial, - process: c.baseClient.process, - pipeline: c.baseClient.processPipeline, - txPipeline: c.baseClient.processTxPipeline, + dial: c.dial, + process: c.process, + pipeline: c.processPipeline, + txPipeline: c.processTxPipeline, }) } From 321a1f6dfd495226a5c6823ac99b612949d76dcb Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Tue, 29 Apr 2025 00:19:23 +0300 Subject: [PATCH 5/5] change staticchecks settings --- .golangci.yml | 11 +++++++++++ json.go | 4 ++-- redis.go | 18 +++++++++--------- sentinel.go | 4 ++-- sentinel_test.go | 2 +- tx.go | 8 ++++---- universal.go | 14 +++++++------- 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index dfd3f260a..872454ff7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,17 @@ run: timeout: 5m tests: false linters: + settings: + staticcheck: + checks: + - all + # Incorrect or missing package comment. + # https://staticcheck.dev/docs/checks/#ST1000 + - -ST1000 + # Omit embedded fields from selector expression. + # https://staticcheck.dev/docs/checks/#QF1008 + - -QF1008 + - -ST1003 exclusions: generated: lax presets: diff --git a/json.go b/json.go index d4479c788..b3cadf4b7 100644 --- a/json.go +++ b/json.go @@ -113,7 +113,7 @@ func (cmd *JSONCmd) Expanded() (interface{}, error) { func (cmd *JSONCmd) readReply(rd *proto.Reader) error { // nil response from JSON.(M)GET (cmd.baseCmd.err will be "redis: nil") - if cmd.Err() == Nil { + if cmd.baseCmd.Err() == Nil { cmd.val = "" return Nil } @@ -182,7 +182,7 @@ func (cmd *JSONSliceCmd) Result() ([]interface{}, error) { } func (cmd *JSONSliceCmd) readReply(rd *proto.Reader) error { - if cmd.Err() == Nil { + if cmd.baseCmd.Err() == Nil { cmd.val = nil return Nil } diff --git a/redis.go b/redis.go index 8521eed59..e0159294d 100644 --- a/redis.go +++ b/redis.go @@ -677,16 +677,16 @@ func NewClient(opt *Options) *Client { func (c *Client) init() { c.cmdable = c.Process c.initHooks(hooks{ - dial: c.dial, - process: c.process, - pipeline: c.processPipeline, - txPipeline: c.processTxPipeline, + dial: c.baseClient.dial, + process: c.baseClient.process, + pipeline: c.baseClient.processPipeline, + txPipeline: c.baseClient.processTxPipeline, }) } func (c *Client) WithTimeout(timeout time.Duration) *Client { clone := *c - clone.baseClient = c.withTimeout(timeout) + clone.baseClient = c.baseClient.withTimeout(timeout) clone.init() return &clone } @@ -839,10 +839,10 @@ func newConn(opt *Options, connPool pool.Pooler) *Conn { c.cmdable = c.Process c.statefulCmdable = c.Process c.initHooks(hooks{ - dial: c.dial, - process: c.process, - pipeline: c.processPipeline, - txPipeline: c.processTxPipeline, + dial: c.baseClient.dial, + process: c.baseClient.process, + pipeline: c.baseClient.processPipeline, + txPipeline: c.baseClient.processTxPipeline, }) return &c diff --git a/sentinel.go b/sentinel.go index d679e451f..f5b9a52d1 100644 --- a/sentinel.go +++ b/sentinel.go @@ -321,8 +321,8 @@ func NewSentinelClient(opt *Options) *SentinelClient { } c.initHooks(hooks{ - dial: c.dial, - process: c.process, + dial: c.baseClient.dial, + process: c.baseClient.process, }) c.connPool = newConnPool(opt, c.dialHook) diff --git a/sentinel_test.go b/sentinel_test.go index cde7f956d..2d481d5fc 100644 --- a/sentinel_test.go +++ b/sentinel_test.go @@ -41,7 +41,7 @@ var _ = Describe("Sentinel resolution", func() { client := redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: sentinelName, SentinelAddrs: sentinelAddrs, - MaxRetries: -1, + MaxRetries: -1, }) err := client.Ping(shortCtx).Err() diff --git a/tx.go b/tx.go index 552fe8db1..039eaf351 100644 --- a/tx.go +++ b/tx.go @@ -39,10 +39,10 @@ func (c *Tx) init() { c.statefulCmdable = c.Process c.initHooks(hooks{ - dial: c.dial, - process: c.process, - pipeline: c.processPipeline, - txPipeline: c.processTxPipeline, + dial: c.baseClient.dial, + process: c.baseClient.process, + pipeline: c.baseClient.processPipeline, + txPipeline: c.baseClient.processTxPipeline, }) } diff --git a/universal.go b/universal.go index 3d91dd493..46d5640da 100644 --- a/universal.go +++ b/universal.go @@ -259,13 +259,13 @@ var ( // NewUniversalClient returns a new multi client. The type of the returned client depends // on the following conditions: // -// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode, -// a FailoverClusterClient is returned. -// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode, -// a sentinel-backed FailoverClient is returned. -// 3. If the number of Addrs is two or more, or IsClusterMode option is specified, -// a ClusterClient is returned. -// 4. Otherwise, a single-node Client is returned. +// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode, +// a FailoverClusterClient is returned. +// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode, +// a sentinel-backed FailoverClient is returned. +// 3. If the number of Addrs is two or more, or IsClusterMode option is specified, +// a ClusterClient is returned. +// 4. Otherwise, a single-node Client is returned. func NewUniversalClient(opts *UniversalOptions) UniversalClient { switch { case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):