forked from mirror/redis
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
|
return req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Shutdown() {
|
func (c *Client) shutdown(modifier string) *StatusReq {
|
||||||
panic("not implemented")
|
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 {
|
func (c *Client) SlaveOf(host, port string) *StatusReq {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package redis_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"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 {
|
type RedisTest struct {
|
||||||
openedConnCount, closedConnCount, initedConnCount int64
|
openedConnCount, closedConnCount, initedConnCount int64
|
||||||
client *redis.Client
|
client *redis.Client
|
||||||
|
@ -29,15 +61,6 @@ var _ = Suite(&RedisTest{})
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func sortStrings(slice []string) []string {
|
|
||||||
sort.Strings(slice)
|
|
||||||
return slice
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func (t *RedisTest) SetUpTest(c *C) {
|
func (t *RedisTest) SetUpTest(c *C) {
|
||||||
if t.client == nil {
|
if t.client == nil {
|
||||||
openConn := func() (net.Conn, error) {
|
openConn := func() (net.Conn, error) {
|
||||||
|
|
Loading…
Reference in New Issue