forked from mirror/ledisdb
Lua script, HMGET, value for absent key #219
This commit is contained in:
parent
e48663b03a
commit
b2f90f832a
|
@ -84,9 +84,26 @@ func (w *luaWriter) writeSliceArray(lst [][]byte) {
|
||||||
|
|
||||||
w.l.CreateTable(len(lst), 0)
|
w.l.CreateTable(len(lst), 0)
|
||||||
for i, v := range lst {
|
for i, v := range lst {
|
||||||
|
if v == nil {
|
||||||
|
w.l.PushBoolean(false)
|
||||||
|
//TNL: not sure what is "expected" behaviour here.
|
||||||
|
//Redis returns "false", but may be "nil" is more appropriate?
|
||||||
|
//For me both variants seems better, then empty string.
|
||||||
|
//
|
||||||
|
//w.l.PushNil()
|
||||||
|
} else {
|
||||||
|
w.l.PushString(hack.String(v))
|
||||||
|
}
|
||||||
|
w.l.RawSeti(-2, i+1)
|
||||||
|
|
||||||
|
/*
|
||||||
|
//TNL: and instead of push nil we can just skip it
|
||||||
|
if v != nil {
|
||||||
w.l.PushString(hack.String(v))
|
w.l.PushString(hack.String(v))
|
||||||
w.l.RawSeti(-2, i+1)
|
w.l.RawSeti(-2, i+1)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *luaWriter) writeFVPairArray(lst []ledis.FVPair) {
|
func (w *luaWriter) writeFVPairArray(lst []ledis.FVPair) {
|
||||||
|
|
|
@ -105,6 +105,15 @@ var testScript5 = `
|
||||||
return ledis.call("PING")
|
return ledis.call("PING")
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var testScript6 = `
|
||||||
|
ledis.call('hmset', 'zzz', 1, 2, 5, 42)
|
||||||
|
local a = ledis.call('hmget', 'zzz', 1, 2, 5, 42)
|
||||||
|
for i = 1, 5 do
|
||||||
|
a[i] = type(a[i])
|
||||||
|
end
|
||||||
|
return a
|
||||||
|
`
|
||||||
|
|
||||||
func TestLuaCall(t *testing.T) {
|
func TestLuaCall(t *testing.T) {
|
||||||
cfg := config.NewConfigDefault()
|
cfg := config.NewConfigDefault()
|
||||||
cfg.Addr = ":11188"
|
cfg.Addr = ":11188"
|
||||||
|
@ -187,5 +196,29 @@ func TestLuaCall(t *testing.T) {
|
||||||
t.Fatal(fmt.Sprintf("%v %T", v, v))
|
t.Fatal(fmt.Sprintf("%v %T", v, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = app.script.l.DoString(testScript6)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v = luaReplyToLedisReply(l)
|
||||||
|
vv := v.([]interface{})
|
||||||
|
expected := []string{
|
||||||
|
"string",
|
||||||
|
"boolean",
|
||||||
|
"string",
|
||||||
|
"boolean",
|
||||||
|
"nil",
|
||||||
|
}
|
||||||
|
if len(expected) != len(vv) {
|
||||||
|
t.Fatalf("length different: %d, %d", len(expected), len(vv))
|
||||||
|
}
|
||||||
|
for i, r := range vv {
|
||||||
|
s := string(r.([]byte))
|
||||||
|
if s != expected[i] {
|
||||||
|
t.Errorf("reply[%d] expected: %s, actual: %s", i, expected[i], s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
luaClient.db = nil
|
luaClient.db = nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue