Skip to content

Commit

Permalink
gofumports
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 16, 2020
1 parent 62469e4 commit 14c843e
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 87 deletions.
1 change: 0 additions & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (s *clusterScenario) addrs() []string {
func (s *clusterScenario) newClusterClientUnsafe(opt *redis.ClusterOptions) *redis.ClusterClient {
opt.Addrs = s.addrs()
return redis.NewClusterClient(opt)

}

func (s *clusterScenario) newClusterClient(
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ func newGeoLocationSliceParser(q *GeoRadiusQuery) proto.MultiBulkParse {
Name: vv,
})
case *GeoLocation:
//TODO: avoid copying
// TODO: avoid copying
locs = append(locs, *vv)
default:
return nil, fmt.Errorf("got %T, expected string or *GeoLocation", v)
Expand Down
10 changes: 6 additions & 4 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,12 @@ type StatefulCmdable interface {
ClientSetName(ctx context.Context, name string) *BoolCmd
}

var _ Cmdable = (*Client)(nil)
var _ Cmdable = (*Tx)(nil)
var _ Cmdable = (*Ring)(nil)
var _ Cmdable = (*ClusterClient)(nil)
var (
_ Cmdable = (*Client)(nil)
_ Cmdable = (*Tx)(nil)
_ Cmdable = (*Ring)(nil)
_ Cmdable = (*ClusterClient)(nil)
)

type cmdable func(ctx context.Context, cmd Cmder) error

Expand Down
88 changes: 35 additions & 53 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var _ = Describe("Commands", func() {
})

Describe("server", func() {

It("should Auth", func() {
cmds, err := client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
pipe.Auth(ctx, "password")
Expand Down Expand Up @@ -267,11 +266,9 @@ var _ = Describe("Commands", func() {
Expect(cmd.LastKeyPos).To(Equal(int8(0)))
Expect(cmd.StepCount).To(Equal(int8(0)))
})

})

Describe("debugging", func() {

It("should DebugObject", func() {
err := client.DebugObject(ctx, "foo").Err()
Expect(err).To(MatchError("ERR no such key"))
Expand Down Expand Up @@ -299,11 +296,9 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(n).NotTo(BeZero())
})

})

Describe("keys", func() {

It("should Del", func() {
err := client.Set(ctx, "key1", "Hello", 0).Err()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -760,11 +755,9 @@ var _ = Describe("Commands", func() {
Expect(type_.Err()).NotTo(HaveOccurred())
Expect(type_.Val()).To(Equal("string"))
})

})

Describe("scanning", func() {

It("should Scan", func() {
for i := 0; i < 1000; i++ {
set := client.Set(ctx, fmt.Sprintf("key%d", i), "hello", 0)
Expand Down Expand Up @@ -815,11 +808,9 @@ var _ = Describe("Commands", func() {
Expect(keys).NotTo(BeEmpty())
Expect(cursor).NotTo(BeZero())
})

})

Describe("strings", func() {

It("should Append", func() {
n, err := client.Exists(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -1253,11 +1244,9 @@ var _ = Describe("Commands", func() {
Expect(strLen.Err()).NotTo(HaveOccurred())
Expect(strLen.Val()).To(Equal(int64(0)))
})

})

Describe("hashes", func() {

It("should HDel", func() {
hSet := client.HSet(ctx, "hash", "key", "hello")
Expect(hSet.Err()).NotTo(HaveOccurred())
Expand Down Expand Up @@ -1438,7 +1427,6 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(slice).To(Equal([]string{"hello1", "hello2"}))
})

})

Describe("hyperloglog", func() {
Expand Down Expand Up @@ -1467,7 +1455,6 @@ var _ = Describe("Commands", func() {
})

Describe("lists", func() {

It("should BLPop", func() {
rPush := client.RPush(ctx, "list1", "a", "b", "c")
Expect(rPush.Err()).NotTo(HaveOccurred())
Expand Down Expand Up @@ -1849,11 +1836,9 @@ var _ = Describe("Commands", func() {
Expect(lRange.Err()).NotTo(HaveOccurred())
Expect(lRange.Val()).To(Equal([]string{}))
})

})

Describe("sets", func() {

It("should SAdd", func() {
sAdd := client.SAdd(ctx, "set", "Hello")
Expect(sAdd.Err()).NotTo(HaveOccurred())
Expand Down Expand Up @@ -2057,7 +2042,6 @@ var _ = Describe("Commands", func() {
sMembers := client.SMembers(ctx, "set")
Expect(sMembers.Err()).NotTo(HaveOccurred())
Expect(sMembers.Val()).To(HaveLen(2))

})

It("should SPopN", func() {
Expand Down Expand Up @@ -2172,11 +2156,9 @@ var _ = Describe("Commands", func() {
Expect(sMembers.Err()).NotTo(HaveOccurred())
Expect(sMembers.Val()).To(HaveLen(5))
})

})

Describe("sorted sets", func() {

It("should BZPopMax", func() {
err := client.ZAdd(ctx, "zset1", &redis.Z{
Score: 1,
Expand Down Expand Up @@ -3400,7 +3382,6 @@ var _ = Describe("Commands", func() {
Member: "two",
}}))
})

})

Describe("streams", func() {
Expand Down Expand Up @@ -3568,13 +3549,15 @@ var _ = Describe("Commands", func() {
It("should XRead", func() {
res, err := client.XReadStreams(ctx, "stream", "0").Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]redis.XStream{{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
}},
Expect(res).To(Equal([]redis.XStream{
{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
},
},
}))

_, err = client.XReadStreams(ctx, "stream", "3").Result()
Expand All @@ -3588,12 +3571,14 @@ var _ = Describe("Commands", func() {
Block: 100 * time.Millisecond,
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]redis.XStream{{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
}},
Expect(res).To(Equal([]redis.XStream{
{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
},
},
}))

_, err = client.XRead(ctx, &redis.XReadArgs{
Expand All @@ -3615,13 +3600,15 @@ var _ = Describe("Commands", func() {
Streams: []string{"stream", ">"},
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]redis.XStream{{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
}},
Expect(res).To(Equal([]redis.XStream{
{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
},
},
}))
})

Expand All @@ -3642,13 +3629,15 @@ var _ = Describe("Commands", func() {
Streams: []string{"stream", "0"},
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]redis.XStream{{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: nil},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
}},
Expect(res).To(Equal([]redis.XStream{
{
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: nil},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
},
},
}))
})

Expand Down Expand Up @@ -3935,7 +3924,6 @@ var _ = Describe("Commands", func() {
})

Describe("marshaling/unmarshaling", func() {

type convTest struct {
value interface{}
wanted string
Expand Down Expand Up @@ -3980,11 +3968,9 @@ var _ = Describe("Commands", func() {
Expect(deref(test.dest)).To(Equal(test.value))
}
})

})

Describe("json marshaling/unmarshaling", func() {

BeforeEach(func() {
value := &numberStruct{Number: 42}
err := client.Set(ctx, "key", value, 0).Err()
Expand All @@ -4003,11 +3989,9 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(value.Number).To(Equal(42))
})

})

Describe("Eval", func() {

It("returns keys and values", func() {
vals, err := client.Eval(
ctx,
Expand All @@ -4028,9 +4012,7 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
})

})

})

type numberStruct struct {
Expand Down
8 changes: 4 additions & 4 deletions example/otel/example-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package main

import (
"context"
"log"
"sync"
"time"

"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8/redisext"
"go.opentelemetry.io/otel/api/global"
meterStdout "go.opentelemetry.io/otel/exporters/metric/stdout"
traceStdout "go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"log"
"sync"
"time"
)

func main() {
Expand Down Expand Up @@ -76,4 +77,3 @@ func main() {
<-time.After(5 * time.Second)
span.End()
}

6 changes: 4 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/go-redis/redis/v8"
)

var ctx = context.Background()
var rdb *redis.Client
var (
ctx = context.Background()
rdb *redis.Client
)

func init() {
rdb = redis.NewClient(&redis.Options{
Expand Down
4 changes: 0 additions & 4 deletions internal/hashtag/hashtag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestGinkgoSuite(t *testing.T) {
}

var _ = Describe("CRC16", func() {

// http://redis.io/topics/cluster-spec#keys-distribution-model
It("should calculate CRC16", func() {
tests := []struct {
Expand All @@ -29,11 +28,9 @@ var _ = Describe("CRC16", func() {
Expect(crc16sum(test.s)).To(Equal(test.n), "for %s", test.s)
}
})

})

var _ = Describe("HashSlot", func() {

It("should calculate hash slots", func() {
tests := []struct {
key string
Expand Down Expand Up @@ -70,5 +67,4 @@ var _ = Describe("HashSlot", func() {
Expect(Slot(test.one)).To(Equal(Slot(test.two)), "for %s <-> %s", test.one, test.two)
}
})

})
1 change: 0 additions & 1 deletion internal/instruments.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ func init() {
metric.WithDescription("the number of connections created"),
)
}

6 changes: 4 additions & 2 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/go-redis/redis/v8/internal"
)

var ErrClosed = errors.New("redis: client is closed")
var ErrPoolTimeout = errors.New("redis: connection pool timeout")
var (
ErrClosed = errors.New("redis: client is closed")
ErrPoolTimeout = errors.New("redis: connection pool timeout")
)

var timers = sync.Pool{
New: func() interface{} {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type writer interface {
io.Writer
io.ByteWriter
//io.StringWriter
// io.StringWriter
WriteString(s string) (n int, err error)
}

Expand Down
Loading

0 comments on commit 14c843e

Please sign in to comment.