使用nginx+lua实现信息访问量统计
根据URI参数后去信息类型和信息ID,通过lua client for memcached插入memcached
代码如下:
require('Memcached')
local args = ngx.req.get_uri_args()
if (ngx.var.remote_addr == '192.168.1.5')
then
local key = args['k']
local class = args['c']
local key = class..':'..key
local memcache = Memcached.Connect('127.0.0.1', 11212)
if (memcache:add(key,1))
then
memcache:get(key)
else
memcache:incr(key);
ngx.print(memcache:get(key))
end
else
ngx.exit(404)
end以上就是本文给大家分享的全部内容了,希望对大家学习LUA脚本能够有所帮助。
相关推荐
郗瑞强 2020-08-16
85590296 2020-07-22
jkzyx 2020-06-29
luotuo 2020-06-26
LinuxJob 2020-06-26
ol0 2020-06-26
清溪算法君老号 2020-06-25
86251043 2020-06-13
CSDN0BLOG 2020-06-09
ol0 2020-05-26
andyhuabing 2020-05-22
程序员俱乐部 2020-05-06
83530391 2020-05-05
ol0 2020-05-02
83530391 2020-04-09
85590296 2020-03-25
carolAnn 2020-03-07
大脸猫脸大 2020-03-03
ol0 2020-02-18