BenchmarkHSETPipelined benchmarks HSET operations using pipelining for better performance
(b *testing.B)
| 182 | |
| 183 | // BenchmarkHSETPipelined benchmarks HSET operations using pipelining for better performance |
| 184 | func BenchmarkHSETPipelined(b *testing.B) { |
| 185 | ctx := context.Background() |
| 186 | |
| 187 | // Setup Redis client |
| 188 | rdb := redis.NewClient(&redis.Options{ |
| 189 | Addr: "localhost:6379", |
| 190 | DB: 0, |
| 191 | }) |
| 192 | defer rdb.Close() |
| 193 | |
| 194 | // Test connection |
| 195 | if err := rdb.Ping(ctx).Err(); err != nil { |
| 196 | b.Skipf("Redis server not available: %v", err) |
| 197 | } |
| 198 | |
| 199 | // Clean up before and after tests |
| 200 | defer func() { |
| 201 | rdb.FlushDB(ctx) |
| 202 | }() |
| 203 | |
| 204 | scales := []int{1, 10, 100, 1000, 10000, 100000} |
| 205 | |
| 206 | for _, scale := range scales { |
| 207 | b.Run(fmt.Sprintf("HSET_Pipelined_%d_operations", scale), func(b *testing.B) { |
| 208 | benchmarkHSETPipelined(b, rdb, ctx, scale) |
| 209 | }) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | func BenchmarkHSET_Concurrent(b *testing.B) { |
| 214 | ctx := context.Background() |