From de6c131865b8263400c8491777b295035f2408e4 Mon Sep 17 00:00:00 2001 From: lintanghui Date: Fri, 18 Feb 2022 11:36:04 +0800 Subject: [PATCH] fix: invalid type assert in stringArg --- bench_test.go | 26 ++++++++++++++++++++++++++ command.go | 9 +++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bench_test.go b/bench_test.go index 5644f50c..ba81ce84 100644 --- a/bench_test.go +++ b/bench_test.go @@ -341,6 +341,32 @@ func BenchmarkClusterPing(b *testing.B) { }) } +func BenchmarkClusterDoInt(b *testing.B) { + if testing.Short() { + b.Skip("skipping in short mode") + } + + ctx := context.Background() + cluster := newClusterScenario() + if err := startCluster(ctx, cluster); err != nil { + b.Fatal(err) + } + defer cluster.Close() + + client := cluster.newClusterClient(ctx, redisClusterOptions()) + defer client.Close() + + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + err := client.Do(ctx, "SET", 10, 10).Err() + if err != nil { + b.Fatal(err) + } + } + }) +} + func BenchmarkClusterSetString(b *testing.B) { if testing.Short() { b.Skip("skipping in short mode") diff --git a/command.go b/command.go index 89e2cd83..98328761 100644 --- a/command.go +++ b/command.go @@ -151,8 +151,13 @@ func (cmd *baseCmd) stringArg(pos int) string { if pos < 0 || pos >= len(cmd.args) { return "" } - s, _ := cmd.args[pos].(string) - return s + arg := cmd.args[pos] + switch v := arg.(type) { + case string: + return v + default: + return fmt.Sprintf("%v", v) + } } func (cmd *baseCmd) firstKeyPos() int8 {