forked from mirror/redis
Merge pull request #139 from go-redis/fix/bench-use-default-port
Fix benchmarks to use Redis on default port and FLUSHDB before run.
This commit is contained in:
commit
c222cc95bf
|
@ -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),
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue