diff --git a/conn.go b/conn.go index f5d85c9..7c3eb40 100644 --- a/conn.go +++ b/conn.go @@ -241,6 +241,15 @@ func (c *Conn) Peek(id uint64) (body []byte, err error) { return c.readResp(r, true, "FOUND %d", &id) } +// ReserveJob reserves the specified job by id from the server. +func (c *Conn) ReserveJob(id uint64) (body []byte, err error) { + r, err := c.cmd(nil, nil, nil, "reserve-job", id) + if err != nil { + return nil, err + } + return c.readResp(r, true, "RESERVED %d", &id) +} + // Stats retrieves global statistics from the server. func (c *Conn) Stats() (map[string]string, error) { r, err := c.cmd(nil, nil, nil, "stats") diff --git a/conn_test.go b/conn_test.go index 8197037..6cd5009 100644 --- a/conn_test.go +++ b/conn_test.go @@ -197,6 +197,21 @@ func TestPeekTwice(t *testing.T) { } } +func TestReserveJob(t *testing.T) { + c := NewConn(mock("reserve-job 1\r\n", "RESERVED 1 1\r\nx\r\n")) + + body, err := c.ReserveJob(1) + if err != nil { + t.Fatal(err) + } + if len(body) != 1 || body[0] != 'x' { + t.Fatalf("bad body, expected %#v, got %#v", "x", string(body)) + } + if err = c.Close(); err != nil { + t.Fatal(err) + } +} + func TestRelease(t *testing.T) { c := NewConn(mock("release 1 3 2\r\n", "RELEASED\r\n"))