diff --git a/client/ledis-py/ledis/client.py b/client/ledis-py/ledis/client.py index 6c8a9fb..cffac29 100644 --- a/client/ledis-py/ledis/client.py +++ b/client/ledis-py/ledis/client.py @@ -912,13 +912,13 @@ class Ledis(object): return self.execute_command('EVALSHA', sha1, len(keys), *keys, *args) def scriptload(self, script): - return self.execute_command('SCRIPT LOAD', script) + return self.execute_command('SCRIPT', 'LOAD', script) def scriptexists(self, *args): - return self.execute_command('SCRIPT EXISTS', *args) + return self.execute_command('SCRIPT', 'EXISTS', *args) def scriptflush(self): - return self.execute_command('SCRIPT FLUSH') + return self.execute_command('SCRIPT', 'FLUSH') class Transaction(Ledis): def __init__(self, connection_pool, response_callbacks): diff --git a/client/nodejs/ledis/lib/commands.js b/client/nodejs/ledis/lib/commands.js index 26408e2..7271f3d 100644 --- a/client/nodejs/ledis/lib/commands.js +++ b/client/nodejs/ledis/lib/commands.js @@ -131,7 +131,5 @@ module.exports = [ "eval", "evalsha", - "script load", - "script exists", - "script flush", + "script", ]; diff --git a/client/openresty/ledis.lua b/client/openresty/ledis.lua index 2778a56..973d489 100644 --- a/client/openresty/ledis.lua +++ b/client/openresty/ledis.lua @@ -156,9 +156,7 @@ local commands = { -- [[script]] "eval", "evalsha", - "script load", - "script exists", - "script flush" + "script" } @@ -398,7 +396,6 @@ function _M.hmset(self, hashname, ...) return _do_cmd(self, "hmset", hashname, ...) end - function _M.array_to_hash(self, t) local n = #t -- print("n = ", n) diff --git a/server/cmd_script.go b/server/cmd_script.go index e5c3264..d2a3a1c 100644 --- a/server/cmd_script.go +++ b/server/cmd_script.go @@ -133,15 +133,19 @@ func scriptCommand(c *client) error { args := c.args - switch strings.ToLower(c.cmd) { - case "script load": + if len(args) < 1 { + return ErrCmdParams + } + + switch strings.ToLower(ledis.String(args[0])) { + case "load": return scriptLoadCommand(c) - case "script exists": + case "exists": return scriptExistsCommand(c) - case "script flush": + case "flush": return scriptFlushCommand(c) default: - return fmt.Errorf("invalid script cmd %s", args[0]) + return fmt.Errorf("invalid script %s", args[0]) } return nil @@ -151,14 +155,14 @@ func scriptLoadCommand(c *client) error { s := c.app.s l := s.l - if len(c.args) != 1 { + if len(c.args) != 2 { return ErrCmdParams } - h := sha1.Sum(c.args[0]) + h := sha1.Sum(c.args[1]) key := hex.EncodeToString(h[0:20]) - if r := l.LoadString(ledis.String(c.args[0])); r != 0 { + if r := l.LoadString(ledis.String(c.args[1])); r != 0 { err := fmt.Errorf("%s", l.ToString(-1)) l.Pop(1) return err @@ -176,12 +180,12 @@ func scriptLoadCommand(c *client) error { func scriptExistsCommand(c *client) error { s := c.app.s - if len(c.args) < 1 { + if len(c.args) < 2 { return ErrCmdParams } - ay := make([]interface{}, len(c.args)) - for i, n := range c.args { + ay := make([]interface{}, len(c.args[1:])) + for i, n := range c.args[1:] { if _, ok := s.chunks[ledis.String(n)]; ok { ay[i] = int64(1) } else { @@ -197,6 +201,10 @@ func scriptFlushCommand(c *client) error { s := c.app.s l := s.l + if len(c.args) != 1 { + return ErrCmdParams + } + for n, _ := range s.chunks { l.PushNil() l.SetGlobal(n) @@ -212,7 +220,5 @@ func scriptFlushCommand(c *client) error { func init() { register("eval", evalCommand) register("evalsha", evalshaCommand) - register("script load", scriptCommand) - register("script flush", scriptCommand) - register("script exists", scriptCommand) + register("script", scriptCommand) } diff --git a/server/cmd_script_test.go b/server/cmd_script_test.go index d652e08..ae3e713 100644 --- a/server/cmd_script_test.go +++ b/server/cmd_script_test.go @@ -25,7 +25,7 @@ func TestCmdEval(t *testing.T) { var sha1 string var err error - if sha1, err = ledis.String(c.Do("script load", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}")); err != nil { + if sha1, err = ledis.String(c.Do("script", "load", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}")); err != nil { t.Fatal(err) } else if len(sha1) != 40 { t.Fatal(sha1) @@ -37,19 +37,19 @@ func TestCmdEval(t *testing.T) { t.Fatal(fmt.Sprintf("%v", v)) } - if ay, err := ledis.Values(c.Do("script exists", sha1, "01234567890123456789")); err != nil { + if ay, err := ledis.Values(c.Do("script", "exists", sha1, "01234567890123456789")); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(ay, []interface{}{int64(1), int64(0)}) { t.Fatal(fmt.Sprintf("%v", ay)) } - if ok, err := ledis.String(c.Do("script flush")); err != nil { + if ok, err := ledis.String(c.Do("script", "flush")); err != nil { t.Fatal(err) } else if ok != "OK" { t.Fatal(ok) } - if ay, err := ledis.Values(c.Do("script exists", sha1)); err != nil { + if ay, err := ledis.Values(c.Do("script", "exists", sha1)); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(ay, []interface{}{int64(0)}) { t.Fatal(fmt.Sprintf("%v", ay))