Merge pull request #534 from go-redis/fix/cleanup

Fix/cleanup
This commit is contained in:
Vladimir Mihailenco 2017-03-24 12:56:31 +02:00 committed by GitHub
commit dc9d5006b3
2 changed files with 43 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package redis_test package redis_test
import ( import (
"bytes"
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
@ -704,3 +705,36 @@ func BenchmarkRedisClusterPing(b *testing.B) {
} }
}) })
} }
func BenchmarkRedisClusterSetString(b *testing.B) {
if testing.Short() {
b.Skip("skipping in short mode")
}
cluster := &clusterScenario{
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
nodeIds: make([]string, 6),
processes: make(map[string]*redisProcess, 6),
clients: make(map[string]*redis.Client, 6),
}
if err := startCluster(cluster); err != nil {
b.Fatal(err)
}
defer stopCluster(cluster)
client := cluster.clusterClient(redisClusterOptions())
defer client.Close()
value := string(bytes.Repeat([]byte{'1'}, 10000))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if err := client.Set("key", value, 0).Err(); err != nil {
b.Fatal(err)
}
}
})
}

View File

@ -2,7 +2,6 @@ package redis
import ( import (
"io" "io"
"strconv"
"time" "time"
"github.com/go-redis/redis/internal" "github.com/go-redis/redis/internal"
@ -19,24 +18,24 @@ func usePrecise(dur time.Duration) bool {
return dur < time.Second || dur%time.Second != 0 return dur < time.Second || dur%time.Second != 0
} }
func formatMs(dur time.Duration) string { func formatMs(dur time.Duration) int64 {
if dur > 0 && dur < time.Millisecond { if dur > 0 && dur < time.Millisecond {
internal.Logf( internal.Logf(
"specified duration is %s, but minimal supported value is %s", "specified duration is %s, but minimal supported value is %s",
dur, time.Millisecond, dur, time.Millisecond,
) )
} }
return strconv.FormatInt(int64(dur/time.Millisecond), 10) return int64(dur / time.Millisecond)
} }
func formatSec(dur time.Duration) string { func formatSec(dur time.Duration) int64 {
if dur > 0 && dur < time.Second { if dur > 0 && dur < time.Second {
internal.Logf( internal.Logf(
"specified duration is %s, but minimal supported value is %s", "specified duration is %s, but minimal supported value is %s",
dur, time.Second, dur, time.Second,
) )
} }
return strconv.FormatInt(int64(dur/time.Second), 10) return int64(dur / time.Second)
} }
type Cmdable interface { type Cmdable interface {
@ -1340,7 +1339,7 @@ func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string)
args := make([]interface{}, 3+len(keys)) args := make([]interface{}, 3+len(keys))
args[0] = "zinterstore" args[0] = "zinterstore"
args[1] = destination args[1] = destination
args[2] = strconv.Itoa(len(keys)) args[2] = len(keys)
for i, key := range keys { for i, key := range keys {
args[3+i] = key args[3+i] = key
} }
@ -1536,7 +1535,7 @@ func (c *cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd
args := make([]interface{}, 3+len(keys)) args := make([]interface{}, 3+len(keys))
args[0] = "zunionstore" args[0] = "zunionstore"
args[1] = dest args[1] = dest
args[2] = strconv.Itoa(len(keys)) args[2] = len(keys)
for i, key := range keys { for i, key := range keys {
args[3+i] = key args[3+i] = key
} }
@ -1755,7 +1754,7 @@ func (c *cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd {
cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs := make([]interface{}, 3+len(keys)+len(args))
cmdArgs[0] = "eval" cmdArgs[0] = "eval"
cmdArgs[1] = script cmdArgs[1] = script
cmdArgs[2] = strconv.Itoa(len(keys)) cmdArgs[2] = len(keys)
for i, key := range keys { for i, key := range keys {
cmdArgs[3+i] = key cmdArgs[3+i] = key
} }
@ -1772,7 +1771,7 @@ func (c *cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd
cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs := make([]interface{}, 3+len(keys)+len(args))
cmdArgs[0] = "evalsha" cmdArgs[0] = "evalsha"
cmdArgs[1] = sha1 cmdArgs[1] = sha1
cmdArgs[2] = strconv.Itoa(len(keys)) cmdArgs[2] = len(keys)
for i, key := range keys { for i, key := range keys {
cmdArgs[3+i] = key cmdArgs[3+i] = key
} }
@ -1984,7 +1983,7 @@ func (c *cmdable) ClusterAddSlots(slots ...int) *StatusCmd {
args[0] = "cluster" args[0] = "cluster"
args[1] = "addslots" args[1] = "addslots"
for i, num := range slots { for i, num := range slots {
args[2+i] = strconv.Itoa(num) args[2+i] = num
} }
cmd := NewStatusCmd(args...) cmd := NewStatusCmd(args...)
c.process(cmd) c.process(cmd)