Fix benchmarks to use Redis on default port and FLUSHDB before run.

This commit is contained in:
Vladimir Mihailenco 2015-07-18 11:22:42 +03:00
parent 2e21f6b3e7
commit ba4682c2a3
3 changed files with 26 additions and 35 deletions

View File

@ -305,6 +305,10 @@ var _ = Describe("Cluster", func() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
func BenchmarkRedisClusterPing(b *testing.B) { func BenchmarkRedisClusterPing(b *testing.B) {
if testing.Short() {
b.Skip("skipping in short mode")
}
cluster := &clusterScenario{ cluster := &clusterScenario{
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"}, ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
nodeIds: make([]string, 6), nodeIds: make([]string, 6),

View File

@ -182,11 +182,9 @@ var _ = Describe("Pool", func() {
}) })
func BenchmarkPool(b *testing.B) { func BenchmarkPool(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: redisAddr,
IdleTimeout: 100 * time.Millisecond,
})
defer client.Close() defer client.Close()
pool := client.Pool() pool := client.Pool()
b.ResetTimer() b.ResetTimer()

View File

@ -169,12 +169,18 @@ var _ = Describe("Client", func() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const benchRedisAddr = ":6379" func benchRedisClient() *redis.Client {
client := redis.NewClient(&redis.Options{
Addr: ":6379",
})
if err := client.FlushDb().Err(); err != nil {
panic(err)
}
return client
}
func BenchmarkRedisPing(b *testing.B) { func BenchmarkRedisPing(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
b.ResetTimer() b.ResetTimer()
@ -189,10 +195,9 @@ func BenchmarkRedisPing(b *testing.B) {
} }
func BenchmarkRedisSet(b *testing.B) { func BenchmarkRedisSet(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
value := string(bytes.Repeat([]byte{'1'}, 10000)) value := string(bytes.Repeat([]byte{'1'}, 10000))
b.ResetTimer() b.ResetTimer()
@ -207,13 +212,8 @@ func BenchmarkRedisSet(b *testing.B) {
} }
func BenchmarkRedisGetNil(b *testing.B) { func BenchmarkRedisGetNil(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
if err := client.FlushDb().Err(); err != nil {
b.Fatal(err)
}
b.ResetTimer() b.ResetTimer()
@ -227,9 +227,7 @@ func BenchmarkRedisGetNil(b *testing.B) {
} }
func BenchmarkRedisGet(b *testing.B) { func BenchmarkRedisGet(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
value := bytes.Repeat([]byte{'1'}, 10000) value := bytes.Repeat([]byte{'1'}, 10000)
@ -253,9 +251,7 @@ func BenchmarkRedisGet(b *testing.B) {
} }
func BenchmarkRedisGetSetBytes(b *testing.B) { func BenchmarkRedisGetSetBytes(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
src := bytes.Repeat([]byte{'1'}, 10000) src := bytes.Repeat([]byte{'1'}, 10000)
@ -280,10 +276,9 @@ func BenchmarkRedisGetSetBytes(b *testing.B) {
} }
func BenchmarkRedisMGet(b *testing.B) { func BenchmarkRedisMGet(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
if err := client.MSet("key1", "hello1", "key2", "hello2").Err(); err != nil { if err := client.MSet("key1", "hello1", "key2", "hello2").Err(); err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -300,9 +295,7 @@ func BenchmarkRedisMGet(b *testing.B) {
} }
func BenchmarkSetExpire(b *testing.B) { func BenchmarkSetExpire(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
b.ResetTimer() b.ResetTimer()
@ -320,9 +313,7 @@ func BenchmarkSetExpire(b *testing.B) {
} }
func BenchmarkPipeline(b *testing.B) { func BenchmarkPipeline(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
b.ResetTimer() b.ResetTimer()
@ -342,9 +333,7 @@ func BenchmarkPipeline(b *testing.B) {
} }
func BenchmarkZAdd(b *testing.B) { func BenchmarkZAdd(b *testing.B) {
client := redis.NewClient(&redis.Options{ client := benchRedisClient()
Addr: benchRedisAddr,
})
defer client.Close() defer client.Close()
b.ResetTimer() b.ResetTimer()