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)
|
return self.execute_command('EVALSHA', sha1, len(keys), *keys, *args)
|
||||||
|
|
||||||
def scriptload(self, script):
|
def scriptload(self, script):
|
||||||
return self.execute_command('SCRIPT LOAD', script)
|
return self.execute_command('SCRIPT', 'LOAD', script)
|
||||||
|
|
||||||
def scriptexists(self, *args):
|
def scriptexists(self, *args):
|
||||||
return self.execute_command('SCRIPT EXISTS', *args)
|
return self.execute_command('SCRIPT', 'EXISTS', *args)
|
||||||
|
|
||||||
def scriptflush(self):
|
def scriptflush(self):
|
||||||
return self.execute_command('SCRIPT FLUSH')
|
return self.execute_command('SCRIPT', 'FLUSH')
|
||||||
|
|
||||||
class Transaction(Ledis):
|
class Transaction(Ledis):
|
||||||
def __init__(self, connection_pool, response_callbacks):
|
def __init__(self, connection_pool, response_callbacks):
|
||||||
|
|
|
@ -131,7 +131,5 @@ module.exports = [
|
||||||
|
|
||||||
"eval",
|
"eval",
|
||||||
"evalsha",
|
"evalsha",
|
||||||
"script load",
|
"script",
|
||||||
"script exists",
|
|
||||||
"script flush",
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -156,9 +156,7 @@ local commands = {
|
||||||
-- [[script]]
|
-- [[script]]
|
||||||
"eval",
|
"eval",
|
||||||
"evalsha",
|
"evalsha",
|
||||||
"script load",
|
"script"
|
||||||
"script exists",
|
|
||||||
"script flush"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,7 +396,6 @@ function _M.hmset(self, hashname, ...)
|
||||||
return _do_cmd(self, "hmset", hashname, ...)
|
return _do_cmd(self, "hmset", hashname, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function _M.array_to_hash(self, t)
|
function _M.array_to_hash(self, t)
|
||||||
local n = #t
|
local n = #t
|
||||||
-- print("n = ", n)
|
-- print("n = ", n)
|
||||||
|
|
|
@ -133,15 +133,19 @@ func scriptCommand(c *client) error {
|
||||||
|
|
||||||
args := c.args
|
args := c.args
|
||||||
|
|
||||||
switch strings.ToLower(c.cmd) {
|
if len(args) < 1 {
|
||||||
case "script load":
|
return ErrCmdParams
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.ToLower(ledis.String(args[0])) {
|
||||||
|
case "load":
|
||||||
return scriptLoadCommand(c)
|
return scriptLoadCommand(c)
|
||||||
case "script exists":
|
case "exists":
|
||||||
return scriptExistsCommand(c)
|
return scriptExistsCommand(c)
|
||||||
case "script flush":
|
case "flush":
|
||||||
return scriptFlushCommand(c)
|
return scriptFlushCommand(c)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid script cmd %s", args[0])
|
return fmt.Errorf("invalid script %s", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -151,14 +155,14 @@ func scriptLoadCommand(c *client) error {
|
||||||
s := c.app.s
|
s := c.app.s
|
||||||
l := s.l
|
l := s.l
|
||||||
|
|
||||||
if len(c.args) != 1 {
|
if len(c.args) != 2 {
|
||||||
return ErrCmdParams
|
return ErrCmdParams
|
||||||
}
|
}
|
||||||
|
|
||||||
h := sha1.Sum(c.args[0])
|
h := sha1.Sum(c.args[1])
|
||||||
key := hex.EncodeToString(h[0:20])
|
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))
|
err := fmt.Errorf("%s", l.ToString(-1))
|
||||||
l.Pop(1)
|
l.Pop(1)
|
||||||
return err
|
return err
|
||||||
|
@ -176,12 +180,12 @@ func scriptLoadCommand(c *client) error {
|
||||||
func scriptExistsCommand(c *client) error {
|
func scriptExistsCommand(c *client) error {
|
||||||
s := c.app.s
|
s := c.app.s
|
||||||
|
|
||||||
if len(c.args) < 1 {
|
if len(c.args) < 2 {
|
||||||
return ErrCmdParams
|
return ErrCmdParams
|
||||||
}
|
}
|
||||||
|
|
||||||
ay := make([]interface{}, len(c.args))
|
ay := make([]interface{}, len(c.args[1:]))
|
||||||
for i, n := range c.args {
|
for i, n := range c.args[1:] {
|
||||||
if _, ok := s.chunks[ledis.String(n)]; ok {
|
if _, ok := s.chunks[ledis.String(n)]; ok {
|
||||||
ay[i] = int64(1)
|
ay[i] = int64(1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,6 +201,10 @@ func scriptFlushCommand(c *client) error {
|
||||||
s := c.app.s
|
s := c.app.s
|
||||||
l := s.l
|
l := s.l
|
||||||
|
|
||||||
|
if len(c.args) != 1 {
|
||||||
|
return ErrCmdParams
|
||||||
|
}
|
||||||
|
|
||||||
for n, _ := range s.chunks {
|
for n, _ := range s.chunks {
|
||||||
l.PushNil()
|
l.PushNil()
|
||||||
l.SetGlobal(n)
|
l.SetGlobal(n)
|
||||||
|
@ -212,7 +220,5 @@ func scriptFlushCommand(c *client) error {
|
||||||
func init() {
|
func init() {
|
||||||
register("eval", evalCommand)
|
register("eval", evalCommand)
|
||||||
register("evalsha", evalshaCommand)
|
register("evalsha", evalshaCommand)
|
||||||
register("script load", scriptCommand)
|
register("script", scriptCommand)
|
||||||
register("script flush", scriptCommand)
|
|
||||||
register("script exists", scriptCommand)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestCmdEval(t *testing.T) {
|
||||||
|
|
||||||
var sha1 string
|
var sha1 string
|
||||||
var err error
|
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)
|
t.Fatal(err)
|
||||||
} else if len(sha1) != 40 {
|
} else if len(sha1) != 40 {
|
||||||
t.Fatal(sha1)
|
t.Fatal(sha1)
|
||||||
|
@ -37,19 +37,19 @@ func TestCmdEval(t *testing.T) {
|
||||||
t.Fatal(fmt.Sprintf("%v", v))
|
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)
|
t.Fatal(err)
|
||||||
} else if !reflect.DeepEqual(ay, []interface{}{int64(1), int64(0)}) {
|
} else if !reflect.DeepEqual(ay, []interface{}{int64(1), int64(0)}) {
|
||||||
t.Fatal(fmt.Sprintf("%v", ay))
|
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)
|
t.Fatal(err)
|
||||||
} else if ok != "OK" {
|
} else if ok != "OK" {
|
||||||
t.Fatal(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)
|
t.Fatal(err)
|
||||||
} else if !reflect.DeepEqual(ay, []interface{}{int64(0)}) {
|
} else if !reflect.DeepEqual(ay, []interface{}{int64(0)}) {
|
||||||
t.Fatal(fmt.Sprintf("%v", ay))
|
t.Fatal(fmt.Sprintf("%v", ay))
|
||||||
|
|
Loading…
Reference in New Issue