您的位置:首页 > 数据库 > Redis

redis 对lua 脚本传出类型的理解

2015-09-30 14:49 537 查看
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)
.


因为这个更加抽象,改动就会少一些。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: