MCPcopy
hub / github.com/redis/go-redis / BenchmarkHSET

Function BenchmarkHSET

hset_benchmark_test.go:36–63  ·  view source on GitHub ↗

HSET Benchmark Tests This file contains benchmark tests for Redis HSET operations with different scales: 1, 10, 100, 1000, 10000, 100000 operations Prerequisites: - Redis server running on localhost:6379 - No authentication required Usage: go test -bench=BenchmarkHSET -v ./hset_benchmark_test.go

(b *testing.B)

Source from the content-addressed store, hash-verified

34
35// BenchmarkHSET benchmarks HSET operations with different scales
36func BenchmarkHSET(b *testing.B) {
37 ctx := context.Background()
38
39 // Setup Redis client
40 rdb := redis.NewClient(&redis.Options{
41 Addr: "localhost:6379",
42 DB: 0,
43 })
44 defer rdb.Close()
45
46 // Test connection
47 if err := rdb.Ping(ctx).Err(); err != nil {
48 b.Skipf("Redis server not available: %v", err)
49 }
50
51 // Clean up before and after tests
52 defer func() {
53 rdb.FlushDB(ctx)
54 }()
55
56 scales := []int{1, 10, 100, 1000, 10000, 100000}
57
58 for _, scale := range scales {
59 b.Run(fmt.Sprintf("HSET_%d_operations", scale), func(b *testing.B) {
60 benchmarkHSETOperations(b, rdb, ctx, scale)
61 })
62 }
63}
64
65// benchmarkHSETOperations performs the actual HSET benchmark for a given scale
66func benchmarkHSETOperations(b *testing.B, rdb *redis.Client, ctx context.Context, operations int) {

Callers

nothing calls this directly

Calls 6

benchmarkHSETOperationsFunction · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
PingMethod · 0.65
FlushDBMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected