Skip to content
Merged
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
24 changes: 24 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,26 @@ 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 {
c.WriteError(msgInvalidInt)
return
}
if timeout < 0 {
c.WriteError(msgTimeoutNegative)
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
13 changes: 13 additions & 0 deletions integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ func TestServer(t *testing.T) {
c.Error("wrong number of arguments", "MEMORY", "USAGE")
c.Error("syntax error", "MEMORY", "USAGE", "too", "many")
})

testRaw(t, func(c *client) {
c.DoLoosely("WAIT", "1", "1")

// Failure cases
c.Error("wrong number", "WAIT", "1")
c.Error("wrong number", "WAIT", "1", "2", "3")
c.Error("wrong number", "WAIT")
c.Error("not an integer", "WAIT", "foo", "0")
c.Error("not an integer", "WAIT", "1", "foo")
// c.Error("out of range", "WAIT", "-1", "0") // something weird going on
c.Error("timeout is negative", "WAIT", "11", "-12")
})
}

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