Skip to content

Commit fc32d0a

Browse files
LINKIWIvladvildanovofekshenawa
authored
Recognize byte slice for key argument in cluster client hash slot computation (#3049)
Co-authored-by: Vladyslav Vildanov <[email protected]> Co-authored-by: ofekshenawa <[email protected]>
1 parent f1ffb55 commit fc32d0a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

command.go

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ func (cmd *baseCmd) stringArg(pos int) string {
167167
switch v := arg.(type) {
168168
case string:
169169
return v
170+
case []byte:
171+
return string(v)
170172
default:
171173
// TODO: consider using appendArg
172174
return fmt.Sprint(v)

osscluster_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,32 @@ var _ = Describe("ClusterClient", func() {
653653
Expect(client.Close()).NotTo(HaveOccurred())
654654
})
655655

656+
It("determines hash slots correctly for generic commands", func() {
657+
opt := redisClusterOptions()
658+
opt.MaxRedirects = -1
659+
client := cluster.newClusterClient(ctx, opt)
660+
661+
err := client.Do(ctx, "GET", "A").Err()
662+
Expect(err).To(Equal(redis.Nil))
663+
664+
err = client.Do(ctx, []byte("GET"), []byte("A")).Err()
665+
Expect(err).To(Equal(redis.Nil))
666+
667+
Eventually(func() error {
668+
return client.SwapNodes(ctx, "A")
669+
}, 30*time.Second).ShouldNot(HaveOccurred())
670+
671+
err = client.Do(ctx, "GET", "A").Err()
672+
Expect(err).To(HaveOccurred())
673+
Expect(err.Error()).To(ContainSubstring("MOVED"))
674+
675+
err = client.Do(ctx, []byte("GET"), []byte("A")).Err()
676+
Expect(err).To(HaveOccurred())
677+
Expect(err.Error()).To(ContainSubstring("MOVED"))
678+
679+
Expect(client.Close()).NotTo(HaveOccurred())
680+
})
681+
656682
It("follows node redirection immediately", func() {
657683
// Configure retry backoffs far in excess of the expected duration of redirection
658684
opt := redisClusterOptions()

0 commit comments

Comments
 (0)