1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

feat: add protocol option (#2598)

This commit is contained in:
ljun20160606
2023-05-16 22:02:22 +08:00
committed by GitHub
parent 31ba855dde
commit 391798880c
11 changed files with 197 additions and 2 deletions

View File

@ -15,6 +15,37 @@ import (
"github.com/redis/go-redis/v9"
)
var _ = Describe("Redis Ring PROTO 2", func() {
const heartbeat = 100 * time.Millisecond
var ring *redis.Ring
BeforeEach(func() {
opt := redisRingOptions()
opt.Protocol = 2
opt.HeartbeatFrequency = heartbeat
ring = redis.NewRing(opt)
err := ring.ForEachShard(ctx, func(ctx context.Context, cl *redis.Client) error {
return cl.FlushDB(ctx).Err()
})
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(ring.Close()).NotTo(HaveOccurred())
})
It("should ring PROTO 2", func() {
_ = ring.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
val, err := c.Do(ctx, "HELLO").Result()
Expect(err).NotTo(HaveOccurred())
Expect(val).Should(ContainElements("proto", int64(2)))
return nil
})
})
})
var _ = Describe("Redis Ring", func() {
const heartbeat = 100 * time.Millisecond
@ -65,6 +96,15 @@ var _ = Describe("Redis Ring", func() {
})
})
It("should ring PROTO 3", func() {
_ = ring.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
val, err := c.Do(ctx, "HELLO").Result()
Expect(err).NotTo(HaveOccurred())
Expect(val).Should(HaveKeyWithValue("proto", int64(3)))
return nil
})
})
It("distributes keys", func() {
setRingKeys()