forked from mirror/ledisdb
bugfix for script command
This commit is contained in:
parent
9628817ca4
commit
b4c66c7eed
|
@ -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):
|
||||
|
|
|
@ -131,7 +131,5 @@ module.exports = [
|
|||
|
||||
"eval",
|
||||
"evalsha",
|
||||
"script load",
|
||||
"script exists",
|
||||
"script flush",
|
||||
"script",
|
||||
];
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue