Skip to content

Commit f99d3b0

Browse files
committed
feat: implement WAIT command as no-op
1 parent ed06249 commit f99d3b0

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Implemented commands:
5757
- TTL
5858
- TYPE
5959
- UNLINK
60+
- WAIT -- no-op
6061
- Transactions (complete)
6162
- DISCARD
6263
- EXEC
@@ -305,8 +306,7 @@ Commands which will probably not be implemented:
305306
- Key
306307
- ~~MIGRATE~~
307308
- ~~OBJECT~~
308-
- ~~WAIT~~
309-
- Scripting
309+
- Scripting
310310
- ~~FCALL / FCALL_RO *~~
311311
- ~~FUNCTION *~~
312312
- ~~SCRIPT DEBUG~~

cmd_generic.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func commandsGeneric(m *Miniredis) {
5656
m.srv.Register("SCAN", m.cmdScan, server.ReadOnlyOption())
5757
// SORT
5858
m.srv.Register("UNLINK", m.cmdDel)
59+
m.srv.Register("WAIT", m.cmdWait)
5960
}
6061

6162
type expireOpts struct {
@@ -773,3 +774,22 @@ func (m *Miniredis) cmdCopy(c *server.Peer, cmd string, args []string) {
773774
c.WriteInt(1)
774775
})
775776
}
777+
778+
// WAIT
779+
func (m *Miniredis) cmdWait(c *server.Peer, cmd string, args []string) {
780+
if !m.isValidCMD(c, cmd, args, exactly(2)) {
781+
return
782+
}
783+
nReplicas, err := strconv.Atoi(args[0])
784+
if err != nil || nReplicas < 0 {
785+
c.WriteError(msgInvalidInt)
786+
return
787+
}
788+
timeout, err := strconv.Atoi(args[1])
789+
if err != nil || timeout < 0 {
790+
c.WriteError(msgInvalidInt)
791+
return
792+
}
793+
// WAIT always returns 0 when called on a standalone instance
794+
c.WriteInt(0)
795+
}

cmd_generic_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,3 +990,27 @@ func TestCopy(t *testing.T) {
990990
)
991991
})
992992
}
993+
994+
func TestWait(t *testing.T) {
995+
_, c := runWithClient(t)
996+
997+
t.Run("success", func(t *testing.T) {
998+
must0(t, c, "WAIT", "2", "100")
999+
must0(t, c, "WAIT", "1", "0")
1000+
})
1001+
1002+
t.Run("errors", func(t *testing.T) {
1003+
mustDo(t, c, "WAIT",
1004+
proto.Error(errWrongNumber("wait")),
1005+
)
1006+
mustDo(t, c, "WAIT", "2",
1007+
proto.Error(errWrongNumber("wait")),
1008+
)
1009+
mustDo(t, c, "WAIT", "2", "bar",
1010+
proto.Error(msgInvalidInt),
1011+
)
1012+
mustDo(t, c, "WAIT", "foo", "100",
1013+
proto.Error(msgInvalidInt),
1014+
)
1015+
})
1016+
}

cmd_scripting_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ func TestCmdEvalResponse(t *testing.T) {
469469
"EVAL", "return redis.call('HMGET','mkey', 'bad', 'key')", "0",
470470
proto.Array(proto.Nil, proto.Nil),
471471
)
472+
473+
mustDo(t, c,
474+
"EVAL", "return redis.call('WAIT', '2', '100')", "0",
475+
proto.Int(0),
476+
)
472477
}
473478

474479
func TestCmdEvalAuth(t *testing.T) {

0 commit comments

Comments
 (0)