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

 

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).

因为这个更加抽象,改动就会少一些。

posted @ 2015-09-30 14:49  百史官  阅读(843)  评论(0)    收藏  举报