Skip to content

Commit 6178b20

Browse files
authored
Merge pull request #1040 from go-redis/feature/hook-new
Feature/hook new
2 parents d025f43 + 4e0b5a1 commit 6178b20

20 files changed

+1148
-1048
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

3-
## Unreleased
3+
## v7 WIP
4+
5+
- WrapProcess is replaced with more convenient AddHook that has access to context.Context.
6+
- WithContext no longer creates shallow copy.
7+
8+
## v6.15
49

510
- Cluster and Ring pipelines process commands for each node in its own goroutine.
611

bench_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package redis_test
22

33
import (
44
"bytes"
5+
"context"
56
"fmt"
67
"strings"
78
"testing"
@@ -198,3 +199,140 @@ func BenchmarkZAdd(b *testing.B) {
198199
}
199200
})
200201
}
202+
203+
var clientSink *redis.Client
204+
205+
func BenchmarkWithContext(b *testing.B) {
206+
rdb := benchmarkRedisClient(10)
207+
defer rdb.Close()
208+
209+
ctx := context.Background()
210+
211+
b.ResetTimer()
212+
b.ReportAllocs()
213+
214+
for i := 0; i < b.N; i++ {
215+
clientSink = rdb.WithContext(ctx)
216+
}
217+
}
218+
219+
var ringSink *redis.Ring
220+
221+
func BenchmarkRingWithContext(b *testing.B) {
222+
rdb := redis.NewRing(&redis.RingOptions{})
223+
defer rdb.Close()
224+
225+
ctx := context.Background()
226+
227+
b.ResetTimer()
228+
b.ReportAllocs()
229+
230+
for i := 0; i < b.N; i++ {
231+
ringSink = rdb.WithContext(ctx)
232+
}
233+
}
234+
235+
//------------------------------------------------------------------------------
236+
237+
func newClusterScenario() *clusterScenario {
238+
return &clusterScenario{
239+
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
240+
nodeIds: make([]string, 6),
241+
processes: make(map[string]*redisProcess, 6),
242+
clients: make(map[string]*redis.Client, 6),
243+
}
244+
}
245+
246+
func BenchmarkClusterPing(b *testing.B) {
247+
if testing.Short() {
248+
b.Skip("skipping in short mode")
249+
}
250+
251+
cluster := newClusterScenario()
252+
if err := startCluster(cluster); err != nil {
253+
b.Fatal(err)
254+
}
255+
defer stopCluster(cluster)
256+
257+
client := cluster.clusterClient(redisClusterOptions())
258+
defer client.Close()
259+
260+
b.ResetTimer()
261+
262+
b.RunParallel(func(pb *testing.PB) {
263+
for pb.Next() {
264+
err := client.Ping().Err()
265+
if err != nil {
266+
b.Fatal(err)
267+
}
268+
}
269+
})
270+
}
271+
272+
func BenchmarkClusterSetString(b *testing.B) {
273+
if testing.Short() {
274+
b.Skip("skipping in short mode")
275+
}
276+
277+
cluster := newClusterScenario()
278+
if err := startCluster(cluster); err != nil {
279+
b.Fatal(err)
280+
}
281+
defer stopCluster(cluster)
282+
283+
client := cluster.clusterClient(redisClusterOptions())
284+
defer client.Close()
285+
286+
value := string(bytes.Repeat([]byte{'1'}, 10000))
287+
288+
b.ResetTimer()
289+
290+
b.RunParallel(func(pb *testing.PB) {
291+
for pb.Next() {
292+
err := client.Set("key", value, 0).Err()
293+
if err != nil {
294+
b.Fatal(err)
295+
}
296+
}
297+
})
298+
}
299+
300+
func BenchmarkClusterReloadState(b *testing.B) {
301+
if testing.Short() {
302+
b.Skip("skipping in short mode")
303+
}
304+
305+
cluster := newClusterScenario()
306+
if err := startCluster(cluster); err != nil {
307+
b.Fatal(err)
308+
}
309+
defer stopCluster(cluster)
310+
311+
client := cluster.clusterClient(redisClusterOptions())
312+
defer client.Close()
313+
314+
b.ResetTimer()
315+
316+
for i := 0; i < b.N; i++ {
317+
err := client.ReloadState()
318+
if err != nil {
319+
b.Fatal(err)
320+
}
321+
}
322+
}
323+
324+
var clusterSink *redis.ClusterClient
325+
326+
func BenchmarkClusterWithContext(b *testing.B) {
327+
rdb := redis.NewClusterClient(&redis.ClusterOptions{})
328+
defer rdb.Close()
329+
330+
ctx := context.Background()
331+
332+
b.ResetTimer()
333+
b.ReportAllocs()
334+
335+
for i := 0; i < b.N; i++ {
336+
clusterSink = rdb.WithContext(ctx)
337+
}
338+
}

0 commit comments

Comments
 (0)