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:
40
ring_test.go
40
ring_test.go
@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user