请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

lua脚本连接redis查询数据时,一直走tomcat后端

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

正在回答 回答被采纳积分+3

1回答

龙虾三少 2021-03-09 17:59:29

先确认下缓存有没有命中 检查下redis里的内容有没有

0 回复 有任何疑惑可以回复我~
  • 好的,我查一下,老师住在慕课网吗?回答好快,哈哈哈哈哈
    回复 有任何疑惑可以回复我~ 2021-03-09 18:04:16
  • 我基本每天会定期回答 碰巧看见了
    回复 有任何疑惑可以回复我~ 2021-03-09 18:32:06
  • 老师,我的@Compont @Bean Redistemplate没起作用,Redistemplate 的key序列化方式是JdkSerializationRedisSerializer  ,redis 的键为"\xac\xed\x00\x05t\x00\bitem_103"
    回复 有任何疑惑可以回复我~ 2021-03-09 19:24:27
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号