lua脚本连接redis查询数据时,一直走tomcat后端
来源:5-18 OpenResty实战---Redis支持

weixin_慕桂英4274529
2021-03-09
itemredis文件:
local args = ngx.req.get_uri_args()
local id = args["id"]
local redis = require "resty.redis"
local cache = redis:new()
local ok,err =cache:connect("127.0.0.1",6379)
local item_model = cache:get("item_"..id)
if (item_model == ngx.null or item_model == nil) then
local resq = ngx.location.capture("/item/get?id="..id)
item_model = resq.body
end
ngx.say(item_model)
conf文件
location /luaitem/get{
default_type "application/json";
content_by_lua_file E:/openResty/openresty-1.19.3.1-win64/lua/itemredis.lua;
}
使用的是redis默认数据库0
Tomcat日志
0:0:0:0:0:0:0:1 - - [09/Mar/2021:17:47:30 +0800] "GET /item/get?id=103 HTTP/1.1" 200 304 15
127.0.0.1 - - [09/Mar/2021:17:47:31 +0800] "GET /favicon.ico HTTP/1.1" 200 92 3
0:0:0:0:0:0:0:1 - - [09/Mar/2021:17:47:33 +0800] "GET /item/get?id=103 HTTP/1.1" 200 304 3
127.0.0.1 - - [09/Mar/2021:17:47:33 +0800] "GET /favicon.ico HTTP/1.1" 200 92 9
0:0:0:0:0:0:0:1 - - [09/Mar/2021:17:47:33 +0800] "GET /item/get?id=103 HTTP/1.1" 200 304 3
127.0.0.1 - - [09/Mar/2021:17:47:33 +0800] "GET /favicon.ico HTTP/1.1" 200 92 3
写回答
1回答
-
龙虾三少
2021-03-09
先确认下缓存有没有命中 检查下redis里的内容有没有
032021-03-09
相似问题
lua脚本连接redis的疑问
回答 2
服务端日志记录的问题
回答 1