Skip to content

Commit

Permalink
Format code and fix go vet (#2696)
Browse files Browse the repository at this point in the history
* run go fix ./...

Signed-off-by: Tiago Peczenyj <[email protected]>

* run make fmt

Signed-off-by: Tiago Peczenyj <[email protected]>

* fix go vet ./... issues

* Update README.md

Reorder imports with the rules defined in the Makefile 

as if we run `make fmt`

* run gofumpt -w .

* update Makefile to use gofumpt instead gofmt

* increment makefile

* format test

* format tests

Signed-off-by: Tiago Peczenyj <[email protected]>

---------

Signed-off-by: Tiago Peczenyj <[email protected]>
Co-authored-by: ofekshenawa <[email protected]>
  • Loading branch information
peczenyj and ofekshenawa authored Sep 20, 2023
1 parent 1a7d2f4 commit e8ad794
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ testdeps: testdata/redis/src/redis-server
bench: testdeps
go test ./... -test.run=NONE -test.bench=. -test.benchmem

.PHONY: all test testdeps bench
.PHONY: all test testdeps bench fmt

testdata/redis:
mkdir -p $@
Expand All @@ -29,7 +29,7 @@ testdata/redis/src/redis-server: testdata/redis
cd $< && make all

fmt:
gofmt -w -s ./
gofumpt -w ./
goimports -w -local github.com/redis/go-redis ./

go_mod_tidy:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ go get github.com/redis/go-redis/v9
```go
import (
"context"
"github.com/redis/go-redis/v9"
"fmt"

"github.com/redis/go-redis/v9"
)

var ctx = context.Background()
Expand Down Expand Up @@ -125,8 +126,9 @@ go-redis also supports connecting via the [redis uri specification](https://gith
```go
import (
"context"
"github.com/redis/go-redis/v9"
"fmt"

"github.com/redis/go-redis/v9"
)

var ctx = context.Background()
Expand Down
3 changes: 2 additions & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"

"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9/internal/hashtag"
)
Expand Down Expand Up @@ -1457,7 +1458,7 @@ var _ = Describe("ClusterClient timeout", func() {
})

var _ = Describe("ClusterClient ParseURL", func() {
var cases = []struct {
cases := []struct {
test string
url string
o *redis.ClusterOptions // expected value
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4324,7 +4324,6 @@ func (cmd *FunctionStatsCmd) readDuration(rd *proto.Reader) (time.Duration, erro
}

func (cmd *FunctionStatsCmd) readCommand(rd *proto.Reader) ([]string, error) {

n, err := rd.ReadArrayLen()
if err != nil {
return nil, err
Expand All @@ -4341,6 +4340,7 @@ func (cmd *FunctionStatsCmd) readCommand(rd *proto.Reader) ([]string, error) {

return command, nil
}

func (cmd *FunctionStatsCmd) readRunningScripts(rd *proto.Reader) ([]RunningScript, bool, error) {
n, err := rd.ReadArrayLen()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ func (info LibraryInfo) Validate() error {

// Hello Set the resp protocol used.
func (c statefulCmdable) Hello(ctx context.Context,
ver int, username, password, clientName string) *MapStringInterfaceCmd {
ver int, username, password, clientName string,
) *MapStringInterfaceCmd {
args := make([]interface{}, 0, 7)
args = append(args, "hello", ver)
if password != "" {
Expand Down
23 changes: 4 additions & 19 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ var _ = Describe("Commands", func() {
})

It("should ClientSetInfo", func() {

pipe := client.Pipeline()

// Test setting the libName
Expand Down Expand Up @@ -413,7 +412,6 @@ var _ = Describe("Commands", func() {
})

It("should filter commands by ACL category", func() {

filter := &redis.FilterBy{
ACLCat: "admin",
}
Expand Down Expand Up @@ -580,7 +578,6 @@ var _ = Describe("Commands", func() {
n, err = client.Exists(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(0)))

})

It("should Keys", func() {
Expand Down Expand Up @@ -727,7 +724,6 @@ var _ = Describe("Commands", func() {
})

It("should PExpireTime", func() {

// The command returns -1 if the key exists but has no associated expiration time.
// The command returns -2 if the key does not exist.
pExpireTime := client.PExpireTime(ctx, "key")
Expand Down Expand Up @@ -966,7 +962,6 @@ var _ = Describe("Commands", func() {
})

It("should ExpireTime", func() {

// The command returns -1 if the key exists but has no associated expiration time.
// The command returns -2 if the key does not exist.
expireTimeCmd := client.ExpireTime(ctx, "key")
Expand All @@ -988,7 +983,6 @@ var _ = Describe("Commands", func() {
})

It("should TTL", func() {

// The command returns -1 if the key exists but has no associated expire
// The command returns -2 if the key does not exist.
ttl := client.TTL(ctx, "key")
Expand Down Expand Up @@ -2042,7 +2036,6 @@ var _ = Describe("Commands", func() {
})

It("should ACL LOG", func() {

err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -2073,7 +2066,6 @@ var _ = Describe("Commands", func() {
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(limitedLogEntries)).To(Equal(2))

})

It("should ACL LOG RESET", func() {
Expand All @@ -2087,7 +2079,6 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(0))
})

})

Describe("hashes", func() {
Expand Down Expand Up @@ -2699,7 +2690,6 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(key).To(Equal("list2"))
Expect(val).To(Equal([]string{"a", "b", "c", "d"}))

})

It("should BLMPopBlocks", func() {
Expand All @@ -2721,15 +2711,15 @@ var _ = Describe("Commands", func() {
case <-done:
Fail("BLMPop is not blocked")
case <-time.After(time.Second):
//ok
// ok
}

_, err := client.LPush(ctx, "list_list", "a").Result()
Expect(err).NotTo(HaveOccurred())

select {
case <-done:
//ok
// ok
case <-time.After(time.Second):
Fail("BLMPop is still blocked")
}
Expand Down Expand Up @@ -4184,7 +4174,6 @@ var _ = Describe("Commands", func() {
})

It("should ZMPop", func() {

err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
Expand Down Expand Up @@ -4256,11 +4245,9 @@ var _ = Describe("Commands", func() {
Score: 6,
Member: "six",
}}))

})

It("should BZMPop", func() {

err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
Expand Down Expand Up @@ -4360,15 +4347,15 @@ var _ = Describe("Commands", func() {
case <-done:
Fail("BZMPop is not blocked")
case <-time.After(time.Second):
//ok
// ok
}

err := client.ZAdd(ctx, "list_list", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())

select {
case <-done:
//ok
// ok
case <-time.After(time.Second):
Fail("BZMPop is still blocked")
}
Expand Down Expand Up @@ -6928,7 +6915,6 @@ var _ = Describe("Commands", func() {

close(started)
})

})

Describe("SlowLogGet", func() {
Expand All @@ -6949,7 +6935,6 @@ var _ = Describe("Commands", func() {
Expect(len(result)).NotTo(BeZero())
})
})

})

type numberStruct struct {
Expand Down
3 changes: 2 additions & 1 deletion doctests/lpush_lrange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package example_commands_test
import (
"context"
"fmt"

"github.com/redis/go-redis/v9"
)

func ExampleLPushLRange() {
func ExampleClient_LPush_and_lrange() {
ctx := context.Background()

rdb := redis.NewClient(&redis.Options{
Expand Down
3 changes: 2 additions & 1 deletion doctests/set_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package example_commands_test
import (
"context"
"fmt"

"github.com/redis/go-redis/v9"
)

func ExampleSetGet() {
func ExampleClient_Set_and_get() {
ctx := context.Background()

rdb := redis.NewClient(&redis.Options{
Expand Down
3 changes: 2 additions & 1 deletion example/del-keys-without-ttl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"sync"
"time"

"github.com/redis/go-redis/v9"
"go.uber.org/zap"

"github.com/redis/go-redis/v9"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion extra/redisotel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"net"
"time"

"github.com/redis/go-redis/v9"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

"github.com/redis/go-redis/v9"
)

// InstrumentMetrics starts reporting OpenTelemetry Metrics.
Expand Down
12 changes: 6 additions & 6 deletions extra/redisprometheus/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ var _ prometheus.Collector = (*Collector)(nil)
// The given namespace and subsystem are used to build the fully qualified metric name,
// i.e. "{namespace}_{subsystem}_{metric}".
// The provided metrics are:
// * pool_hit_total
// * pool_miss_total
// * pool_timeout_total
// * pool_conn_total_current
// * pool_conn_idle_current
// * pool_conn_stale_total
// - pool_hit_total
// - pool_miss_total
// - pool_timeout_total
// - pool_conn_total_current
// - pool_conn_idle_current
// - pool_conn_stale_total
func NewCollector(namespace, subsystem string, getter StatGetter) *Collector {
return &Collector{
getter: getter,
Expand Down
1 change: 1 addition & 0 deletions internal/customvet/checks/setval/setval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go/ast"
"go/token"
"go/types"

"golang.org/x/tools/go/analysis"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/customvet/checks/setval/setval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package setval_test
import (
"testing"

"github.com/redis/go-redis/internal/customvet/checks/setval"
"golang.org/x/tools/go/analysis/analysistest"

"github.com/redis/go-redis/internal/customvet/checks/setval"
)

func Test(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/customvet/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/redis/go-redis/internal/customvet/checks/setval"
"golang.org/x/tools/go/analysis/multichecker"

"github.com/redis/go-redis/internal/customvet/checks/setval"
)

func main() {
Expand Down
1 change: 0 additions & 1 deletion internal/pool/conn_check.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos

package pool

Expand Down
1 change: 0 additions & 1 deletion internal/pool/conn_check_dummy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !illumos
// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos

package pool

Expand Down
1 change: 0 additions & 1 deletion internal/pool/conn_check_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos

package pool

Expand Down
1 change: 0 additions & 1 deletion internal/util/safe.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build appengine
// +build appengine

package util

Expand Down
1 change: 0 additions & 1 deletion internal/util/unsafe.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !appengine
// +build !appengine

package util

Expand Down
6 changes: 4 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ const (
sentinelPort3 = "9128"
)

var redisPort = "6380"
var redisAddr = ":" + redisPort
var (
redisPort = "6380"
redisAddr = ":" + redisPort
)

var (
sentinelAddrs = []string{":" + sentinelPort1, ":" + sentinelPort2, ":" + sentinelPort3}
Expand Down
1 change: 0 additions & 1 deletion options_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build go1.7
// +build go1.7

package redis

Expand Down
1 change: 1 addition & 0 deletions probabilistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func NewBFInfoCmd(ctx context.Context, args ...interface{}) *BFInfoCmd {
func (cmd *BFInfoCmd) SetVal(val BFInfo) {
cmd.val = val
}

func (cmd *BFInfoCmd) String() string {
return cmdString(cmd, cmd.val)
}
Expand Down
Loading

0 comments on commit e8ad794

Please sign in to comment.