Last active
January 3, 2016 13:29
-
-
Save pahud/8470143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--package.path = package.path .. ';/opt/openresty/lualib/?.lua' | |
local redis = require "resty.redis" | |
local cjson = require "cjson" | |
local red_host = 'xxx.xxx.xxx.xxx' | |
local ts = os.time() | |
local red = redis:new() | |
--local tb_resp = {} | |
--local req_args = ngx.req.get_uri_args() | |
red:set_timeout(10000) -- 10 sec | |
local ok, err = red:connect(red_host, 6379) | |
function hset(key, field, value ) | |
return red:hset(key, field, value) | |
end | |
res, err = red:zrevrangebyscore('chat:rcv:1' , "("..ts, 0, 'withscores', 'limit', 0, 100 ) | |
res = red:array_to_hash(res) | |
--ngx.say( type(res) ) | |
local threads = {} | |
for f,v in pairs(res) do | |
ngx.say(f..'=>'..v) | |
t = ngx.thread.spawn(hset, 'pahud:hash', f, v) | |
table.insert(threads, t) | |
end | |
for i = 1, #threads do | |
local ok, res = ngx.thread.wait(threads[i]) | |
if not ok then | |
ngx.say('err - '.. res) | |
else | |
ngx.say('good ') | |
end | |
end | |
ngx.eof() | |
local ok, err = red:set_keepalive(300000, 50000) | |
if not ok then | |
print("[ERROR]failed to set redis keepalive: ", err) | |
return | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment