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:]
}
if c.cmd == "xuse" {
err := c.handleUseThenCmd()
if c.cmd == "xselect" {
err := c.handleXSelectCmd()
if err != nil {
c.resp.writeError(err)
c.resp.flush()
@ -182,26 +182,26 @@ func (c *respClient) handleRequest(reqData [][]byte) error {
return nil
}
// XUSE db THEN command
func (c *respClient) handleUseThenCmd() error {
// XSELECT db THEN command
func (c *respClient) handleXSelectCmd() error {
if len(c.args) <= 2 {
// 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" {
// 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]))
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)
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

View File

@ -5,14 +5,14 @@ import (
"testing"
)
func TestXuse(t *testing.T) {
func TestXSelect(t *testing.T) {
c1 := getTestConn()
defer c1.Close()
c2 := getTestConn()
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 {
t.Fatal(err)
}
@ -22,7 +22,7 @@ func TestXuse(t *testing.T) {
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 {
t.Fatal(n)
}