标签:数据 访问 配置 ima roc bsp 数据分析 ash span
luarocks install hashids
location /test {
content_by_lua_block {
-- 此处为伪代码,需要自己处理,代码见下面的
ngx.say(hashid)
}
}
local hashids = require("hashids");
local redis = require "resty.redis"
local red = redis:new()
local ids= 1;
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return
end
ids, err = red:incrby("ids", 1)
if not ok then
ngx.say("failed to set ids: ", err)
return
end
-- ngx.say("set result: ", ok)
local ok, err = red:set_keepalive(10000, 100)
if not ok then
ngx.say("failed to set keepalive: ", err)
return
end
local h = hashids.new("dalong")
hash = h:encode(ids)
ngx.say(hash)
local hashids = require("hashids");
local h = hashids.new("dalong")
hash = h:decode("y71ZEKxm")
print(hash[1])
实际系统如果使用还需要考虑redis 的高可用,安全,以及如何进行数据分析的问题
openresty && hashids&& redis 生成短链接
标签:数据 访问 配置 ima roc bsp 数据分析 ash span
原文地址:http://www.cnblogs.com/rongfengliang/p/7043596.html