Skip to content

Commit 91171f5

Browse files
committed
feat: add ClientUnpause
1 parent a15a89e commit 91171f5

File tree

3 files changed

+128
-4
lines changed

3 files changed

+128
-4
lines changed

command.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,13 +2649,14 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
26492649

26502650
// subtract start and end.
26512651
nodes := make([]ClusterNode, n-2)
2652+
26522653
for j := 0; j < len(nodes); j++ {
26532654
nn, err := rd.ReadArrayLen()
26542655
if err != nil {
26552656
return err
26562657
}
2657-
if nn != 2 && nn != 3 {
2658-
return fmt.Errorf("got %d elements in cluster info address, expected 2 or 3", nn)
2658+
if nn < 2 || nn > 4 {
2659+
return fmt.Errorf("got %d elements in cluster info address, expected 2, 3, or 4", n)
26592660
}
26602661

26612662
ip, err := rd.ReadString()
@@ -2670,14 +2671,43 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
26702671

26712672
nodes[j].Addr = net.JoinHostPort(ip, port)
26722673

2673-
if nn == 3 {
2674+
if nn >= 3 {
26742675
id, err := rd.ReadString()
26752676
if err != nil {
26762677
return err
26772678
}
26782679
nodes[j].ID = id
26792680
}
2681+
2682+
if nn >= 4 {
2683+
networkingMetadata := make(map[string]string)
2684+
2685+
metadataLength, err := rd.ReadArrayLen()
2686+
if err != nil {
2687+
return err
2688+
}
2689+
2690+
if metadataLength%2 != 0 {
2691+
return fmt.Errorf(
2692+
"got %d elements in metadata, expected an even number", metadataLength)
2693+
}
2694+
2695+
for i := 0; i < metadataLength; i += 2 {
2696+
key, err := rd.ReadString()
2697+
if err != nil {
2698+
return err
2699+
}
2700+
value, err := rd.ReadString()
2701+
if err != nil {
2702+
return err
2703+
}
2704+
networkingMetadata[key] = value
2705+
}
2706+
2707+
nodes[j].NetworkingMetadata = networkingMetadata
2708+
}
26802709
}
2710+
26812711
cmd.val[i] = ClusterSlot{
26822712
Start: int(start),
26832713
End: int(end),

commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ type Cmdable interface {
310310
ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd
311311
ClientList(ctx context.Context) *StringCmd
312312
ClientPause(ctx context.Context, dur time.Duration) *BoolCmd
313+
ClientUnpause(ctx context.Context) *BoolCmd
313314
ClientID(ctx context.Context) *IntCmd
314315
ClientUnblock(ctx context.Context, id int64) *IntCmd
315316
ClientUnblockWithError(ctx context.Context, id int64) *IntCmd
@@ -2818,6 +2819,12 @@ func (c cmdable) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd {
28182819
return cmd
28192820
}
28202821

2822+
func (c cmdable) ClientUnpause(ctx context.Context) *BoolCmd {
2823+
cmd := NewBoolCmd(ctx, "client", "unpause")
2824+
_ = c(ctx, cmd)
2825+
return cmd
2826+
}
2827+
28212828
func (c cmdable) ClientID(ctx context.Context) *IntCmd {
28222829
cmd := NewIntCmd(ctx, "client", "id")
28232830
_ = c(ctx, cmd)

internal/pool/main_test.go

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package pool_test
22

33
import (
44
"context"
5+
"fmt"
56
"net"
67
"sync"
8+
"syscall"
79
"testing"
10+
"time"
811

912
. "github.com/onsi/ginkgo"
1013
. "github.com/onsi/gomega"
@@ -32,5 +35,89 @@ func perform(n int, cbs ...func(int)) {
3235
}
3336

3437
func dummyDialer(context.Context) (net.Conn, error) {
35-
return &net.TCPConn{}, nil
38+
return newDummyConn(), nil
39+
}
40+
41+
func newDummyConn() net.Conn {
42+
return &dummyConn{
43+
rawConn: new(dummyRawConn),
44+
}
45+
}
46+
47+
var (
48+
_ net.Conn = (*dummyConn)(nil)
49+
_ syscall.Conn = (*dummyConn)(nil)
50+
)
51+
52+
type dummyConn struct {
53+
rawConn *dummyRawConn
54+
}
55+
56+
func (d *dummyConn) SyscallConn() (syscall.RawConn, error) {
57+
return d.rawConn, nil
58+
}
59+
60+
var errDummy = fmt.Errorf("dummyConn err")
61+
62+
func (d *dummyConn) Read(b []byte) (n int, err error) {
63+
return 0, errDummy
64+
}
65+
66+
func (d *dummyConn) Write(b []byte) (n int, err error) {
67+
return 0, errDummy
68+
}
69+
70+
func (d *dummyConn) Close() error {
71+
d.rawConn.Close()
72+
return nil
73+
}
74+
75+
func (d *dummyConn) LocalAddr() net.Addr {
76+
return &net.TCPAddr{}
77+
}
78+
79+
func (d *dummyConn) RemoteAddr() net.Addr {
80+
return &net.TCPAddr{}
81+
}
82+
83+
func (d *dummyConn) SetDeadline(t time.Time) error {
84+
return nil
85+
}
86+
87+
func (d *dummyConn) SetReadDeadline(t time.Time) error {
88+
return nil
89+
}
90+
91+
func (d *dummyConn) SetWriteDeadline(t time.Time) error {
92+
return nil
93+
}
94+
95+
var _ syscall.RawConn = (*dummyRawConn)(nil)
96+
97+
type dummyRawConn struct {
98+
mu sync.Mutex
99+
closed bool
100+
}
101+
102+
func (d *dummyRawConn) Control(f func(fd uintptr)) error {
103+
return nil
104+
}
105+
106+
func (d *dummyRawConn) Read(f func(fd uintptr) (done bool)) error {
107+
d.mu.Lock()
108+
defer d.mu.Unlock()
109+
if d.closed {
110+
return fmt.Errorf("dummyRawConn closed")
111+
}
112+
return nil
113+
}
114+
115+
func (d *dummyRawConn) Write(f func(fd uintptr) (done bool)) error {
116+
return nil
117+
}
118+
119+
func (d *dummyRawConn) Close() {
120+
d.mu.Lock()
121+
d.closed = true
122+
d.mu.Unlock()
36123
}

0 commit comments

Comments
 (0)