Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Implemented commands:
- TTL
- TYPE
- UNLINK
- WAIT -- no-op
- Transactions (complete)
- DISCARD
- EXEC
Expand Down Expand Up @@ -305,7 +306,6 @@ Commands which will probably not be implemented:
- Key
- ~~MIGRATE~~
- ~~OBJECT~~
- ~~WAIT~~
- Scripting
- ~~FCALL / FCALL_RO *~~
- ~~FUNCTION *~~
Expand Down
20 changes: 20 additions & 0 deletions cmd_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func commandsGeneric(m *Miniredis) {
m.srv.Register("SCAN", m.cmdScan, server.ReadOnlyOption())
// SORT
m.srv.Register("UNLINK", m.cmdDel)
m.srv.Register("WAIT", m.cmdWait)
}

type expireOpts struct {
Expand Down Expand Up @@ -773,3 +774,22 @@ func (m *Miniredis) cmdCopy(c *server.Peer, cmd string, args []string) {
c.WriteInt(1)
})
}

// WAIT
func (m *Miniredis) cmdWait(c *server.Peer, cmd string, args []string) {
if !m.isValidCMD(c, cmd, args, exactly(2)) {
return
}
nReplicas, err := strconv.Atoi(args[0])
if err != nil || nReplicas < 0 {
c.WriteError(msgInvalidInt)
return
}
timeout, err := strconv.Atoi(args[1])
if err != nil || timeout < 0 {
c.WriteError(msgInvalidInt)
return
}
// WAIT always returns 0 when called on a standalone instance
c.WriteInt(0)
}
24 changes: 24 additions & 0 deletions cmd_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,27 @@ func TestCopy(t *testing.T) {
)
})
}

func TestWait(t *testing.T) {
_, c := runWithClient(t)

t.Run("success", func(t *testing.T) {
must0(t, c, "WAIT", "2", "100")
must0(t, c, "WAIT", "1", "0")
})

t.Run("errors", func(t *testing.T) {
mustDo(t, c, "WAIT",
proto.Error(errWrongNumber("wait")),
)
mustDo(t, c, "WAIT", "2",
proto.Error(errWrongNumber("wait")),
)
mustDo(t, c, "WAIT", "2", "bar",
proto.Error(msgInvalidInt),
)
mustDo(t, c, "WAIT", "foo", "100",
proto.Error(msgInvalidInt),
)
})
}
5 changes: 5 additions & 0 deletions cmd_scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ func TestCmdEvalResponse(t *testing.T) {
"EVAL", "return redis.call('HMGET','mkey', 'bad', 'key')", "0",
proto.Array(proto.Nil, proto.Nil),
)

mustDo(t, c,
"EVAL", "return redis.call('WAIT', '2', '100')", "0",
proto.Int(0),
)
}

func TestCmdEvalAuth(t *testing.T) {
Expand Down