mirror of https://github.com/go-redis/redis.git
Add SHUTDOWN command.
This commit is contained in:
parent
b6ae953e1c
commit
e40a6041e1
25
commands.go
25
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 {
|
||||
|
|
|
@ -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 <nil>:[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) {
|
||||
|
|
Loading…
Reference in New Issue