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里的内容有没有

0
3
weixin_慕桂英4274529
回复
龙虾三少
老师,我的@Compont @Bean Redistemplate没起作用,Redistemplate 的key序列化方式是JdkSerializationRedisSerializer ,redis 的键为"\xac\xed\x00\x05t\x00\bitem_103"
2021-03-09
共3条回复

聚焦Java性能优化 打造亿级流量秒杀系统(赠秒杀项目)

理解高流量电商网站性能构建思路 用高逼格技术解决性能提升问题

2174 学习 · 1009 问题

查看课程