Home >Backend Development >PHP Tutorial >Convert redis data (table) into json in lua-redis

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

WBOY
WBOYOriginal
2016-08-08 09:29:251593browse
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.

Statement:
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
Previous article:php mysql PDO useNext article:php mysql PDO use