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
Lua table with a single
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
Lua table with a single
对于这二种情况,我考虑是 不打算 使用 {ok="ok"} {err="err"} 这种形式,
我更加趋向使用
因为这个更加抽象,改动就会少一些。
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
okfield -> Redis status reply
Lua table with a single
errfield -> 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
okfield -> Redis status reply
Lua table with a single
errfield -> Redis error reply
对于这二种情况,我考虑是 不打算 使用 {ok="ok"} {err="err"} 这种形式,
我更加趋向使用
redis.error_reply(error_string)和redis.status_reply(status_string).
因为这个更加抽象,改动就会少一些。
相关文章推荐
- redis 配置说明
- StackExchange.Redis 使用 - 事件(五)
- redis的备份
- redis安装、配置、命令
- spring集成redis cluster
- nodejs+socketio+redis 简单消息推送实例(一)
- redis安装 phpredis Jedis 扩展的实现及注意事项,php,java,python相关插件安装实例代码和文档推荐
- redis存取二进制数据
- StackExchange.Redis 使用-配置 (四)
- Redis 文档(一)
- 「Redis实例」序列化和反序列化
- redis学习笔记
- Nosql数据库——redis(四)数据类型
- redis导库
- Nosql数据库——redis(三)数据类型
- 解密Redis持久化
- StackExchange.Redis 使用-同步 异步 即发即弃 (三)
- [转]避免误用 Redis
- redis windows 配置
- StackExchange.Redis 使用-发布订阅 (二)