Skip to content

Commit eae9d24

Browse files
committed
123
1 parent 1b7d66f commit eae9d24

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local delay = 5
2+
local handler
3+
handler = function (premature,param)
4+
-- do some routine job in Lua just like a cron job
5+
if premature then
6+
return
7+
end
8+
9+
ngx.log(ngx.ERR, "param is : ", param)
10+
end
11+
12+
local ok, err = ngx.timer.at(delay, handler,"Hello Tinywan")
13+
14+
--[[
15+
curl http://127.0.0.1/ngx_timer_at
16+
17+
2017/05/04 23:24:38 [error] 95933#0: *433016 [lua] get_timer_at.lua:9: param is : Hello Tinywan, context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:80
18+
--]]

Openresty/test.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local red = redis:new()
2+
3+
-- set Cache cache_ngx
4+
function set_to_cache(key,value,exptime)
5+
if not exptime then
6+
exptime = 0
7+
end
8+
local cache_ngx = ngx.shared.cache_ngx
9+
local succ, err, forcible = cache_ngx:set(key,value,exptime)
10+
return succ
11+
end
12+
13+
--get Cache cache_ngx
14+
function get_from_cache(key)
15+
local cache_ngx = ngx.shared.cache_ngx
16+
local value = cache_ngx:get(key)
17+
if not value then
18+
value = nil
19+
set_to_cache(key, value)
20+
end
21+
return value
22+
end
23+
24+
function get_from_redis(key)
25+
local res, err = red:get("dog")
26+
if res then
27+
return 'yes'
28+
else
29+
return 'No'
30+
end
31+
end
32+
local res = get_from_cache('dog')
33+
ngx.say(res)
34+
35+
36+
local delay = 5
37+
local handler
38+
handler = function (premature,param)
39+
-- do some routine job in Lua just like a cron job
40+
if premature then
41+
return
42+
end
43+
44+
ngx.log(ngx.ERR, "param is : ", param)
45+
end
46+
47+
local ok, err = ngx.timer.at(delay, handler,"Hello Tinywan")
48+

0 commit comments

Comments
 (0)