diff --git a/cluster_test.go b/cluster_test.go index 9173faea..136340cc 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -305,6 +305,10 @@ var _ = Describe("Cluster", func() { //------------------------------------------------------------------------------ func BenchmarkRedisClusterPing(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), diff --git a/pool_test.go b/pool_test.go index a4fa76e2..bff892cc 100644 --- a/pool_test.go +++ b/pool_test.go @@ -182,11 +182,9 @@ var _ = Describe("Pool", func() { }) func BenchmarkPool(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: redisAddr, - IdleTimeout: 100 * time.Millisecond, - }) + client := benchRedisClient() defer client.Close() + pool := client.Pool() b.ResetTimer() diff --git a/redis_test.go b/redis_test.go index 3c0d6358..1122df9a 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -189,10 +195,9 @@ func BenchmarkRedisPing(b *testing.B) { } func BenchmarkRedisSet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() + value := string(bytes.Repeat([]byte{'1'}, 10000)) b.ResetTimer() @@ -207,13 +212,8 @@ func BenchmarkRedisSet(b *testing.B) { } func BenchmarkRedisGetNil(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() - if err := client.FlushDb().Err(); err != nil { - b.Fatal(err) - } b.ResetTimer() @@ -227,9 +227,7 @@ func BenchmarkRedisGetNil(b *testing.B) { } func BenchmarkRedisGet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() value := bytes.Repeat([]byte{'1'}, 10000) @@ -253,9 +251,7 @@ func BenchmarkRedisGet(b *testing.B) { } func BenchmarkRedisGetSetBytes(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() src := bytes.Repeat([]byte{'1'}, 10000) @@ -280,10 +276,9 @@ func BenchmarkRedisGetSetBytes(b *testing.B) { } func BenchmarkRedisMGet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() + if err := client.MSet("key1", "hello1", "key2", "hello2").Err(); err != nil { b.Fatal(err) } @@ -300,9 +295,7 @@ func BenchmarkRedisMGet(b *testing.B) { } func BenchmarkSetExpire(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -320,9 +313,7 @@ func BenchmarkSetExpire(b *testing.B) { } func BenchmarkPipeline(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -342,9 +333,7 @@ func BenchmarkPipeline(b *testing.B) { } func BenchmarkZAdd(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer()