Skip to content

Commit 10b3668

Browse files
authored
Merge pull request #1940 from ffenix113/master
Update some argument counts in allocs.
2 parents dabd395 + f6974eb commit 10b3668

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

bench_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"strconv"
78
"strings"
89
"sync"
910
"testing"
@@ -233,6 +234,45 @@ func BenchmarkZAdd(b *testing.B) {
233234
})
234235
}
235236

237+
func BenchmarkXRead(b *testing.B) {
238+
ctx := context.Background()
239+
client := benchmarkRedisClient(ctx, 10)
240+
defer client.Close()
241+
242+
args := redis.XAddArgs{
243+
Stream: "1",
244+
ID: "*",
245+
Values: map[string]string{"uno": "dos"},
246+
}
247+
248+
lenStreams := 16
249+
streams := make([]string, 0, lenStreams)
250+
for i := 0; i < lenStreams; i++ {
251+
streams = append(streams, strconv.Itoa(i))
252+
}
253+
for i := 0; i < lenStreams; i++ {
254+
streams = append(streams, "0")
255+
}
256+
257+
b.ReportAllocs()
258+
b.ResetTimer()
259+
260+
b.RunParallel(func(pb *testing.PB) {
261+
for pb.Next() {
262+
client.XAdd(ctx, &args)
263+
264+
err := client.XRead(ctx, &redis.XReadArgs{
265+
Streams: streams,
266+
Count: 1,
267+
Block: time.Second,
268+
}).Err()
269+
if err != nil {
270+
b.Fatal(err)
271+
}
272+
}
273+
})
274+
}
275+
236276
var clientSink *redis.Client
237277

238278
func BenchmarkWithContext(b *testing.B) {

commands.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ type XReadArgs struct {
17781778
}
17791779

17801780
func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
1781-
args := make([]interface{}, 0, 5+len(a.Streams))
1781+
args := make([]interface{}, 0, 6+len(a.Streams))
17821782
args = append(args, "xread")
17831783

17841784
keyPos := int8(1)
@@ -1860,7 +1860,7 @@ type XReadGroupArgs struct {
18601860
}
18611861

18621862
func (c cmdable) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd {
1863-
args := make([]interface{}, 0, 8+len(a.Streams))
1863+
args := make([]interface{}, 0, 10+len(a.Streams))
18641864
args = append(args, "xreadgroup", "group", a.Group, a.Consumer)
18651865

18661866
keyPos := int8(4)
@@ -1957,7 +1957,7 @@ func (c cmdable) XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAuto
19571957
}
19581958

19591959
func xAutoClaimArgs(ctx context.Context, a *XAutoClaimArgs) []interface{} {
1960-
args := make([]interface{}, 0, 9)
1960+
args := make([]interface{}, 0, 8)
19611961
args = append(args, "xautoclaim", a.Stream, a.Group, a.Consumer, formatMs(ctx, a.MinIdle), a.Start)
19621962
if a.Count > 0 {
19631963
args = append(args, "count", a.Count)
@@ -1989,7 +1989,7 @@ func (c cmdable) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCm
19891989
}
19901990

19911991
func xClaimArgs(a *XClaimArgs) []interface{} {
1992-
args := make([]interface{}, 0, 4+len(a.Messages))
1992+
args := make([]interface{}, 0, 5+len(a.Messages))
19931993
args = append(args,
19941994
"xclaim",
19951995
a.Stream,

0 commit comments

Comments
 (0)