Convert redis data (table) into json in lua-redis

WBOY
Release: 2016-08-08 09:29:25
Original
1527 people have browsed it
There is no corresponding relationship between key and val in the hash data obtained through lua-redis.
The data structure is as follows
1 key1
2 val1
3 key2
4 val2
In order to facilitate other language programs to obtain formatted data, It needs to be converted to json to match key and val. The following modifications have been made in the program (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));
can then be parsed by other languages ​​

The above introduces the conversion of redis data (table) into json in lua-redis, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!