Skip to content

Commit

Permalink
fix: invalid type assert in stringArg
Browse files Browse the repository at this point in the history
  • Loading branch information
lintanghui committed Feb 18, 2022
1 parent a034b08 commit de6c131
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 26 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit de6c131

Please sign in to comment.