標籤:
Lua 到 Redis 的轉換表。
- Lua number -> Redis integer reply (the number is converted into an integer)
- Lua string -> Redis bulk reply
- Lua table (array) -> Redis multi bulk reply (truncated to the first nil inside the Lua array if any)
- Lua table with a single
ok field -> Redis status reply
- Lua table with a single
err field -> Redis error reply
- Lua boolean false -> Redis Nil bulk reply.
總結 redis 只認lua的number,string, table 的數組 , table.ok,table.err,從redis 的返回的類型也可以想到這一點。
也就是說你想這樣
return {name="foo", passwd="bar"} 這樣是不行的
也就是說 redis 為什麼要在lua 放進 cjson,cmsgpack庫的原因, 你傳複雜的類型出去只能這樣。
- Lua table with a single
ok field -> Redis status reply
- Lua table with a single
err field -> Redis error reply
對於這二種情況,我考慮是 不打算 使用 {ok="ok"} {err="err"} 這種形式,
我更加趨向使用redis.error_reply(error_string)和redis.status_reply(status_string).
因為這個更加抽象,改動就會少一些。
redis 對lua 指令碼傳出類型的理解