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