- 国内企业使用nginx的还是挺多的,我在工作的过程中,也经常使用nginx;下面就简单记录一下lua访问redis
local cjson = require "cjson" local redis = require "resty.redis" local red = redis:new() -- 设置后续操作的超时(以毫秒为单位)保护,包括connect方法 red:set_timeout(60000) -- 连接redis;两个参数分别是IP以及端口号 local ok, err = red:connect("xxx.xxx.xxx.xxx", 6379) if not ok then return end -- 设置连接密码 red:auth("xxxx") -- 切换数据库,不设置,默认是0库 red:select(1) local json_results={} local request_method = ngx.var.request_method if request_method == "GET" then json_results["userTag"] = 0 local value = cjson.encode(json_results) ngx.say(value) return elseif request_method == "POST" then ngx.req.read_body() args= ngx.req.get_body_data() end local arg=cjson.decode(args) if (type(arg["userIdList"]) == "nil") or (arg["userId
nginx lua读redis
最新推荐文章于 2024-07-23 07:11:22 发布
本文主要介绍了如何在企业环境中,利用Nginx的Lua模块与Redis进行数据交互,为读者提供了一个简单易懂的实践记录。
摘要由CSDN通过智能技术生成