Redis data (table) in lua-redis is converted to json

Source: Internet
Author: User
: This article mainly describes how to convert redis data (table) to json in lua-redis. if you are interested in PHP tutorials, refer to it. 通过lua-redis获取的hash数据中key,val并非对应关系,
The data structure is as follows:
1 key1
2 val1
3 key2
4 val2

为了便于其他语言程序拿到格式化的数据,需要将其转换为json,让key和val对应起来,程序中做了如下修改(lua)

For k, v in pairs (OK) do
For key, val in pairs (v) do
If key % 2 = 0 then
Tmp [v [key-1] = v [key];
End
End
Ret [k] = tmp;
End
Ngx. say (cjson. encode (ret ));

之后就可以被其他语言解析出来了

以上就介绍了lua-redis中redis数据(table)转换成json,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.