1.目的
实现生成随机的key,从redis中取出该key的值(string类型和hash类型)
2.配置nginx
lua_package_path "/usr/local/lua/?.lua;;"; //在http中增加
location /test {
default_type 'text/plain';
content_by_lua_file /usr/local/luascript/radmstr.lua;
}
3.lua脚本(string类型)
local redis = require "resty.redis"
local json = require "json"
--connect
local cache = redis.new()
local ok, err = cache.connect(cache, '127.0.0.1', '6379')
cache:set_timeout(1000)
if not ok then
ngx.say("failed to connect:", err)
return
end
--random num
local radmnum=math.random(0, 10000