mirror of https://github.com/go-redis/redis.git
gofumports
This commit is contained in:
parent
62469e4f42
commit
14c843ef89
|
@ -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(
|
||||
|
|
10
commands.go
10
commands.go
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
@ -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"))
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -1438,7 +1427,6 @@ var _ = Describe("Commands", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(slice).To(Equal([]string{"hello1", "hello2"}))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Describe("hyperloglog", func() {
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -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() {
|
||||
|
@ -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,
|
||||
|
@ -3400,7 +3382,6 @@ var _ = Describe("Commands", func() {
|
|||
Member: "two",
|
||||
}}))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Describe("streams", func() {
|
||||
|
@ -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{{
|
||||
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()
|
||||
|
@ -3588,12 +3571,14 @@ var _ = Describe("Commands", func() {
|
|||
Block: 100 * time.Millisecond,
|
||||
}).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal([]redis.XStream{{
|
||||
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{
|
||||
|
@ -3615,13 +3600,15 @@ var _ = Describe("Commands", func() {
|
|||
Streams: []string{"stream", ">"},
|
||||
}).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal([]redis.XStream{{
|
||||
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"}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -3642,13 +3629,15 @@ var _ = Describe("Commands", func() {
|
|||
Streams: []string{"stream", "0"},
|
||||
}).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal([]redis.XStream{{
|
||||
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"}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -3935,7 +3924,6 @@ var _ = Describe("Commands", func() {
|
|||
})
|
||||
|
||||
Describe("marshaling/unmarshaling", func() {
|
||||
|
||||
type convTest struct {
|
||||
value interface{}
|
||||
wanted string
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -2,6 +2,10 @@ 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"
|
||||
|
@ -9,9 +13,6 @@ import (
|
|||
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() {
|
||||
|
@ -76,4 +77,3 @@ func main() {
|
|||
<-time.After(5 * time.Second)
|
||||
span.End()
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -70,5 +67,4 @@ var _ = Describe("HashSlot", func() {
|
|||
Expect(Slot(test.one)).To(Equal(Slot(test.two)), "for %s <-> %s", test.one, test.two)
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -29,4 +29,3 @@ func init() {
|
|||
metric.WithDescription("the number of connections created"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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{} {
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
var _ = Describe("ScanIterator", func() {
|
||||
var client *redis.Client
|
||||
|
||||
var seed = func(n int) error {
|
||||
seed := func(n int) error {
|
||||
pipe := client.Pipeline()
|
||||
for i := 1; i <= n; i++ {
|
||||
pipe.Set(ctx, fmt.Sprintf("K%02d", i), "x", 0).Err()
|
||||
|
@ -21,7 +21,7 @@ var _ = Describe("ScanIterator", func() {
|
|||
return err
|
||||
}
|
||||
|
||||
var extraSeed = func(n int, m int) error {
|
||||
extraSeed := func(n int, m int) error {
|
||||
pipe := client.Pipeline()
|
||||
for i := 1; i <= m; i++ {
|
||||
pipe.Set(ctx, fmt.Sprintf("A%02d", i), "x", 0).Err()
|
||||
|
@ -33,8 +33,8 @@ var _ = Describe("ScanIterator", func() {
|
|||
return err
|
||||
}
|
||||
|
||||
var hashKey = "K_HASHTEST"
|
||||
var hashSeed = func(n int) error {
|
||||
hashKey := "K_HASHTEST"
|
||||
hashSeed := func(n int) error {
|
||||
pipe := client.Pipeline()
|
||||
for i := 1; i <= n; i++ {
|
||||
pipe.HSet(ctx, hashKey, fmt.Sprintf("K%02d", i), "x").Err()
|
||||
|
|
|
@ -15,9 +15,11 @@ type scripter interface {
|
|||
ScriptLoad(ctx context.Context, script string) *StringCmd
|
||||
}
|
||||
|
||||
var _ scripter = (*Client)(nil)
|
||||
var _ scripter = (*Ring)(nil)
|
||||
var _ scripter = (*ClusterClient)(nil)
|
||||
var (
|
||||
_ scripter = (*Client)(nil)
|
||||
_ scripter = (*Ring)(nil)
|
||||
_ scripter = (*ClusterClient)(nil)
|
||||
)
|
||||
|
||||
type Script struct {
|
||||
src, hash string
|
||||
|
|
|
@ -181,9 +181,11 @@ type UniversalClient interface {
|
|||
Close() error
|
||||
}
|
||||
|
||||
var _ UniversalClient = (*Client)(nil)
|
||||
var _ UniversalClient = (*ClusterClient)(nil)
|
||||
var _ UniversalClient = (*Ring)(nil)
|
||||
var (
|
||||
_ UniversalClient = (*Client)(nil)
|
||||
_ UniversalClient = (*ClusterClient)(nil)
|
||||
_ UniversalClient = (*Ring)(nil)
|
||||
)
|
||||
|
||||
// NewUniversalClient returns a new multi client. The type of client returned depends
|
||||
// on the following three conditions:
|
||||
|
|
|
@ -37,5 +37,4 @@ var _ = Describe("UniversalClient", func() {
|
|||
})
|
||||
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue