Skip to content

Commit 8ad0124

Browse files
authored
Add support for resp3 protocol (#1739)
* support resp3 protocol Signed-off-by: monkey <[email protected]> * Upgrade mod version limit go1.14 #1715 (comment) Signed-off-by: monkey <[email protected]> * Remove the redundant check of ReadReply Signed-off-by: monkey <[email protected]> * fix the problem Signed-off-by: monkey <[email protected]> * workflows add v9 Signed-off-by: monkey <[email protected]> * update StringStringMapCmd to MapStringStringCmd Signed-off-by: monkey <[email protected]>
1 parent 8d87a75 commit 8ad0124

18 files changed

+1321
-1055
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [master]
66
pull_request:
7-
branches: [master]
7+
branches: [master, v9]
88

99
jobs:
1010
build:

bench_decode_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ type ClientStub struct {
1818
resp []byte
1919
}
2020

21+
var initHello = []byte("%1\r\n+proto\r\n:3\r\n")
22+
2123
func NewClientStub(resp []byte) *ClientStub {
2224
stub := &ClientStub{
2325
resp: resp,
2426
}
27+
2528
stub.Cmdable = NewClient(&Options{
2629
PoolSize: 128,
2730
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
28-
return stub.stubConn(), nil
31+
return stub.stubConn(initHello), nil
2932
},
3033
})
3134
return stub
@@ -40,7 +43,7 @@ func NewClusterClientStub(resp []byte) *ClientStub {
4043
PoolSize: 128,
4144
Addrs: []string{"127.0.0.1:6379"},
4245
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
43-
return stub.stubConn(), nil
46+
return stub.stubConn(initHello), nil
4447
},
4548
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
4649
return []ClusterSlot{
@@ -65,18 +68,27 @@ func NewClusterClientStub(resp []byte) *ClientStub {
6568
return stub
6669
}
6770

68-
func (c *ClientStub) stubConn() *ConnStub {
71+
func (c *ClientStub) stubConn(init []byte) *ConnStub {
6972
return &ConnStub{
73+
init: init,
7074
resp: c.resp,
7175
}
7276
}
7377

7478
type ConnStub struct {
79+
init []byte
7580
resp []byte
7681
pos int
7782
}
7883

7984
func (c *ConnStub) Read(b []byte) (n int, err error) {
85+
// Return conn.init()
86+
if len(c.init) > 0 {
87+
n = copy(b, c.init)
88+
c.init = c.init[n:]
89+
return n, nil
90+
}
91+
8092
if len(c.resp) == 0 {
8193
return 0, io.EOF
8294
}

cluster.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,12 +1392,7 @@ func (c *ClusterClient) txPipelineReadQueued(
13921392
return err
13931393
}
13941394

1395-
switch line[0] {
1396-
case proto.ErrorReply:
1397-
return proto.ParseErrorReply(line)
1398-
case proto.ArrayReply:
1399-
// ok
1400-
default:
1395+
if line[0] != proto.RespArray {
14011396
return fmt.Errorf("redis: expected '*', but got line %q", line)
14021397
}
14031398

cluster_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,16 +1182,17 @@ var _ = Describe("ClusterClient with unavailable Cluster", func() {
11821182
var client *redis.ClusterClient
11831183

11841184
BeforeEach(func() {
1185-
for _, node := range cluster.clients {
1186-
err := node.ClientPause(ctx, 5*time.Second).Err()
1187-
Expect(err).NotTo(HaveOccurred())
1188-
}
1189-
11901185
opt := redisClusterOptions()
11911186
opt.ReadTimeout = 250 * time.Millisecond
11921187
opt.WriteTimeout = 250 * time.Millisecond
11931188
opt.MaxRedirects = 1
11941189
client = cluster.newClusterClientUnstable(opt)
1190+
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
1191+
1192+
for _, node := range cluster.clients {
1193+
err := node.ClientPause(ctx, 5*time.Second).Err()
1194+
Expect(err).NotTo(HaveOccurred())
1195+
}
11951196
})
11961197

11971198
AfterEach(func() {

0 commit comments

Comments
 (0)