码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-09-30 16:14:23      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

 

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 脚本传出类型的理解

标签:

原文地址:http://www.cnblogs.com/ux-lsl/p/4849202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!