rename XUSE to XSELECT

This commit is contained in:
siddontang 2015-03-22 08:39:20 +08:00
parent 5223f5d8eb
commit c412943bf8
2 changed files with 11 additions and 11 deletions

View File

@ -160,8 +160,8 @@ func (c *respClient) handleRequest(reqData [][]byte) error {
c.args = reqData[1:] c.args = reqData[1:]
} }
if c.cmd == "xuse" { if c.cmd == "xselect" {
err := c.handleUseThenCmd() err := c.handleXSelectCmd()
if err != nil { if err != nil {
c.resp.writeError(err) c.resp.writeError(err)
c.resp.flush() c.resp.flush()
@ -182,26 +182,26 @@ func (c *respClient) handleRequest(reqData [][]byte) error {
return nil return nil
} }
// XUSE db THEN command // XSELECT db THEN command
func (c *respClient) handleUseThenCmd() error { func (c *respClient) handleXSelectCmd() error {
if len(c.args) <= 2 { if len(c.args) <= 2 {
// invalid command format // invalid command format
return fmt.Errorf("invalid format for XUSE, must XUSE db THEN your command") return fmt.Errorf("invalid format for XSELECT, must XSELECT db THEN your command")
} }
if hack.String(upperSlice(c.args[1])) != "THEN" { if hack.String(upperSlice(c.args[1])) != "THEN" {
// invalid command format, just resturn here // invalid command format, just resturn here
return fmt.Errorf("invalid format for XUSE, must XUSE db THEN your command") return fmt.Errorf("invalid format for XSELECT, must XSELECT db THEN your command")
} }
index, err := strconv.Atoi(hack.String(c.args[0])) index, err := strconv.Atoi(hack.String(c.args[0]))
if err != nil { if err != nil {
return fmt.Errorf("invalid db for XUSE, err %v", err) return fmt.Errorf("invalid db for XSELECT, err %v", err)
} }
db, err := c.app.ldb.Select(index) db, err := c.app.ldb.Select(index)
if err != nil { if err != nil {
return fmt.Errorf("invalid db for XUSE, err %v", err) return fmt.Errorf("invalid db for XSELECT, err %v", err)
} }
c.db = db c.db = db

View File

@ -5,14 +5,14 @@ import (
"testing" "testing"
) )
func TestXuse(t *testing.T) { func TestXSelect(t *testing.T) {
c1 := getTestConn() c1 := getTestConn()
defer c1.Close() defer c1.Close()
c2 := getTestConn() c2 := getTestConn()
defer c2.Close() defer c2.Close()
_, err := c1.Do("XUSE", "1", "THEN", "SET", "tmp_select_key", "1") _, err := c1.Do("XSELECT", "1", "THEN", "SET", "tmp_select_key", "1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -22,7 +22,7 @@ func TestXuse(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
n, _ := goredis.Int(c2.Do("XUSE", "1", "THEN", "GET", "tmp_select_key")) n, _ := goredis.Int(c2.Do("XSELECT", "1", "THEN", "GET", "tmp_select_key"))
if n != 1 { if n != 1 {
t.Fatal(n) t.Fatal(n)
} }