Skip to content

Commit

Permalink
Recognize byte slice for key argument in cluster client hash slot com…
Browse files Browse the repository at this point in the history
…putation
  • Loading branch information
LINKIWI committed Jul 31, 2024
1 parent 00d9848 commit 3cd7c33
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (cmd *baseCmd) stringArg(pos int) string {
switch v := arg.(type) {
case string:
return v
case []byte:
return string(v)
default:
// TODO: consider using appendArg
return fmt.Sprint(v)
Expand Down
26 changes: 26 additions & 0 deletions osscluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,32 @@ var _ = Describe("ClusterClient", func() {
Expect(client.Close()).NotTo(HaveOccurred())
})

It("determines hash slots correctly for generic commands", func() {
opt := redisClusterOptions()
opt.MaxRedirects = -1
client := cluster.newClusterClient(ctx, opt)

err := client.Do(ctx, "GET", "A").Err()
Expect(err).To(Equal(redis.Nil))

err = client.Do(ctx, []byte("GET"), []byte("A")).Err()
Expect(err).To(Equal(redis.Nil))

Eventually(func() error {
return client.SwapNodes(ctx, "A")
}, 30*time.Second).ShouldNot(HaveOccurred())

err = client.Do(ctx, "GET", "A").Err()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("MOVED"))

err = client.Do(ctx, []byte("GET"), []byte("A")).Err()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("MOVED"))

Expect(client.Close()).NotTo(HaveOccurred())
})

It("follows node redirection immediately", func() {
// Configure retry backoffs far in excess of the expected duration of redirection
opt := redisClusterOptions()
Expand Down

0 comments on commit 3cd7c33

Please sign in to comment.