diff --git a/bench_test.go b/bench_test.go index 5e532ea..708da5d 100644 --- a/bench_test.go +++ b/bench_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "strings" + "sync" "testing" "time" @@ -27,20 +28,44 @@ func benchmarkRedisClient(ctx context.Context, poolSize int) *redis.Client { func BenchmarkRedisPing(b *testing.B) { ctx := context.Background() - client := benchmarkRedisClient(ctx, 10) - defer client.Close() + rdb := benchmarkRedisClient(ctx, 10) + defer rdb.Close() b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { - if err := client.Ping(ctx).Err(); err != nil { + if err := rdb.Ping(ctx).Err(); err != nil { b.Fatal(err) } } }) } +func BenchmarkSetGoroutines(b *testing.B) { + ctx := context.Background() + rdb := benchmarkRedisClient(ctx, 10) + defer rdb.Close() + + for i := 0; i < b.N; i++ { + var wg sync.WaitGroup + + for i := 0; i < 1000; i++ { + wg.Add(1) + go func() { + defer wg.Done() + + err := rdb.Set(ctx, "hello", "world", 0).Err() + if err != nil { + panic(err) + } + }() + } + + wg.Wait() + } +} + func BenchmarkRedisGetNil(b *testing.B) { ctx := context.Background() client := benchmarkRedisClient(ctx, 10)