1
1
package main
2
2
3
3
import (
4
+ "context"
4
5
"flag"
5
6
"fmt"
6
7
hdrhistogram "github.com/HdrHistogram/hdrhistogram-go"
7
- "github.com/mediocregopher/radix/v3 "
8
+ "github.com/mediocregopher/radix/v4 "
8
9
"golang.org/x/time/rate"
9
10
"log"
10
11
"math"
@@ -37,15 +38,15 @@ func stringWithCharset(length int, charset string) string {
37
38
return string (b )
38
39
}
39
40
40
- func ingestionRoutine (conn radix. Client , enableMultiExec bool , datapointsChan chan datapoint , continueOnError bool , cmdS []string , keyspacelen , datasize , number_samples uint64 , loop bool , debug_level int , wg * sync.WaitGroup , keyplace , dataplace int , useLimiter bool , rateLimiter * rate.Limiter , waitReplicas , waitReplicasMs int ) {
41
+ func ingestionRoutine (conn Client , enableMultiExec bool , datapointsChan chan datapoint , continueOnError bool , cmdS []string , keyspacelen , datasize , number_samples uint64 , loop bool , debug_level int , wg * sync.WaitGroup , keyplace , dataplace int , useLimiter bool , rateLimiter * rate.Limiter , waitReplicas , waitReplicasMs int ) {
41
42
defer wg .Done ()
42
43
for i := 0 ; uint64 (i ) < number_samples || loop ; i ++ {
43
44
rawCurrentCmd , key , _ := keyBuildLogic (keyplace , dataplace , datasize , keyspacelen , cmdS )
44
45
sendCmdLogic (conn , rawCurrentCmd , enableMultiExec , key , datapointsChan , continueOnError , debug_level , useLimiter , rateLimiter , waitReplicas , waitReplicasMs )
45
46
}
46
47
}
47
48
48
- func keyBuildLogic (keyPos int , dataPos int , datasize , keyspacelen uint64 , cmdS []string ) (cmd radix.CmdAction , key string , keySlot uint16 ) {
49
+ func keyBuildLogic (keyPos int , dataPos int , datasize , keyspacelen uint64 , cmdS []string ) (cmd radix.Action , key string , keySlot uint16 ) {
49
50
newCmdS := cmdS
50
51
if keyPos > - 1 {
51
52
newCmdS [keyPos ] = fmt .Sprintf ("%d" , rand .Int63n (int64 (keyspacelen )))
@@ -54,22 +55,23 @@ func keyBuildLogic(keyPos int, dataPos int, datasize, keyspacelen uint64, cmdS [
54
55
newCmdS [dataPos ] = stringWithCharset (int (datasize ), charset )
55
56
}
56
57
rawCmd := radix .Cmd (nil , newCmdS [0 ], newCmdS [1 :]... )
57
-
58
58
return rawCmd , key , radix .ClusterSlot ([]byte (newCmdS [1 ]))
59
59
}
60
60
61
- func sendCmdLogic (conn radix.Client , cmd radix.CmdAction , enableMultiExec bool , key string , datapointsChan chan datapoint , continueOnError bool , debug_level int , useRateLimiter bool , rateLimiter * rate.Limiter , waitReplicas , waitReplicasMs int ) {
61
+ func sendCmdLogic (conn Client , cmd radix.Action , enableMultiExec bool , key string , datapointsChan chan datapoint , continueOnError bool , debug_level int , useRateLimiter bool , rateLimiter * rate.Limiter , waitReplicas , waitReplicasMs int ) {
62
+ ctx := context .Background ()
63
+
62
64
if useRateLimiter {
63
65
r := rateLimiter .ReserveN (time .Now (), int (1 ))
64
66
time .Sleep (r .Delay ())
65
67
}
66
68
var err error
67
69
startT := time .Now ()
68
70
if enableMultiExec {
69
- err = conn .Do (radix .WithConn (key , func (c radix.Conn ) error {
71
+ err = conn .Do (ctx , radix .WithConn (key , func (ctx context. Context , c radix.Conn ) error {
70
72
71
73
// Begin the transaction with a MULTI command
72
- if err := conn .Do (radix .Cmd (nil , "MULTI" )); err != nil {
74
+ if err := conn .Do (ctx , radix .Cmd (nil , "MULTI" )); err != nil {
73
75
log .Fatalf ("Received an error while preparing for MULTI: %v, error: %v" , cmd , err )
74
76
}
75
77
@@ -83,25 +85,28 @@ func sendCmdLogic(conn radix.Client, cmd radix.CmdAction, enableMultiExec bool,
83
85
// The return from DISCARD doesn't matter. If it's an error then
84
86
// it's a network error and the Conn will be closed by the
85
87
// client.
86
- conn .Do (radix .Cmd (nil , "DISCARD" ))
88
+ conn .Do (ctx , radix .Cmd (nil , "DISCARD" ))
87
89
log .Fatalf ("Received an error while in multi: %v, error: %v" , cmd , err )
88
90
}
89
91
}()
90
92
91
93
// queue up the transaction's commands
92
- err = conn .Do (cmd )
94
+ err = conn .Do (ctx , cmd )
93
95
94
96
// execute the transaction, capturing the result in a Tuple. We only
95
97
// care about the first element (the result from GET), so we discard the
96
98
// second by setting nil.
97
- return conn .Do (radix .Cmd (nil , "EXEC" ))
99
+ return conn .Do (ctx , radix .Cmd (nil , "EXEC" ))
98
100
}))
99
101
} else if waitReplicas > 0 {
100
- // pipeline the command + wait
101
- err = conn .Do (radix .Pipeline (cmd ,
102
- radix .Cmd (nil , "WAIT" , fmt .Sprintf ("%d" , waitReplicas ), fmt .Sprintf ("%d" , waitReplicasMs ))))
102
+ // Create a new pipeline for the WAIT command
103
+ p := radix .NewPipeline ()
104
+ // Pass both cmd and waitCmd to the original pipeline
105
+ p .Append (cmd )
106
+ p .Append (radix .Cmd (nil , "WAIT" , fmt .Sprintf ("%d" , waitReplicas ), fmt .Sprintf ("%d" , waitReplicasMs )))
107
+ err = conn .Do (ctx , p )
103
108
} else {
104
- err = conn .Do (cmd )
109
+ err = conn .Do (ctx , cmd )
105
110
}
106
111
endT := time .Now ()
107
112
if err != nil {
@@ -134,6 +139,7 @@ func main() {
134
139
clusterMode := flag .Bool ("oss-cluster" , false , "Enable OSS cluster mode." )
135
140
loop := flag .Bool ("l" , false , "Loop. Run the tests forever." )
136
141
version := flag .Bool ("v" , false , "Output version and exit" )
142
+ resp := flag .Int ("resp" , 2 , "redis command response protocol (2 - RESP 2, 3 - RESP 3)" )
137
143
flag .Parse ()
138
144
git_sha := toolGitSHA1 ()
139
145
git_dirty_str := ""
@@ -173,9 +179,14 @@ func main() {
173
179
samplesPerClient := * numberRequests / * clients
174
180
client_update_tick := 1
175
181
latencies = hdrhistogram .New (1 , 90000000 , 3 )
176
- opts := make ([] radix.DialOpt , 0 )
182
+ opts := radix.Dialer {}
177
183
if * password != "" {
178
- opts = append (opts , radix .DialAuthPass (* password ))
184
+ opts .AuthPass = * password
185
+ }
186
+ if * resp == 2 {
187
+ opts .Protocol = "2"
188
+ } else if * resp == 3 {
189
+ opts .Protocol = "3"
179
190
}
180
191
ips , _ := net .LookupIP (* host )
181
192
fmt .Printf ("IPs %v\n " , ips )
@@ -191,7 +202,6 @@ func main() {
191
202
fmt .Printf ("Using random seed: %d\n " , * seed )
192
203
rand .Seed (* seed )
193
204
var cluster * radix.Cluster
194
-
195
205
datapointsChan := make (chan datapoint , * numberRequests )
196
206
for channel_id := 1 ; uint64 (channel_id ) <= * clients ; channel_id ++ {
197
207
wg .Add (1 )
0 commit comments