diff --git a/commands.go b/commands.go index 20ad871..1c04a96 100644 --- a/commands.go +++ b/commands.go @@ -1006,8 +1006,29 @@ func (c *Client) Save() *StatusReq { return req } -func (c *Client) Shutdown() { - panic("not implemented") +func (c *Client) shutdown(modifier string) *StatusReq { + var args []string + if modifier == "" { + args = []string{"SHUTDOWN"} + } else { + args = []string{"SHUTDOWN", modifier} + } + req := NewStatusReq(args...) + c.Process(req) + c.Close() + return req +} + +func (c *Client) Shutdown() *StatusReq { + return c.shutdown("") +} + +func (c *Client) ShutdownSave() *StatusReq { + return c.shutdown("SAVE") +} + +func (c *Client) ShutdownNoSave() *StatusReq { + return c.shutdown("NOSAVE") } func (c *Client) SlaveOf(host, port string) *StatusReq { diff --git a/redis_test.go b/redis_test.go index de6d595..048adfd 100644 --- a/redis_test.go +++ b/redis_test.go @@ -3,6 +3,7 @@ package redis_test import ( "bytes" "fmt" + "io" "net" "runtime" "sort" @@ -20,6 +21,37 @@ const redisAddr = ":6379" //------------------------------------------------------------------------------ +func sortStrings(slice []string) []string { + sort.Strings(slice) + return slice +} + +//------------------------------------------------------------------------------ + +type RedisShutdownTest struct { + client *redis.Client +} + +var _ = Suite(&RedisShutdownTest{}) + +func (t *RedisShutdownTest) SetUpTest(c *C) { + t.client = redis.NewTCPClient(redisAddr, "", -1) +} + +func (t *RedisShutdownTest) TestShutdown(c *C) { + c.Skip("shutdowns server") + + shutdown := t.client.Shutdown() + c.Check(shutdown.Err(), Equals, io.EOF) + c.Check(shutdown.Val(), Equals, "") + + ping := t.client.Ping() + c.Check(ping.Err(), ErrorMatches, "dial tcp :[0-9]+: connection refused") + c.Check(ping.Val(), Equals, "") +} + +//------------------------------------------------------------------------------ + type RedisTest struct { openedConnCount, closedConnCount, initedConnCount int64 client *redis.Client @@ -29,15 +61,6 @@ var _ = Suite(&RedisTest{}) func Test(t *testing.T) { TestingT(t) } -//------------------------------------------------------------------------------ - -func sortStrings(slice []string) []string { - sort.Strings(slice) - return slice -} - -//------------------------------------------------------------------------------ - func (t *RedisTest) SetUpTest(c *C) { if t.client == nil { openConn := func() (net.Conn, error) {