lua脚本连接redis的疑问
来源:5-18 OpenResty实战---Redis支持

weixin_慕设计2423553
2019-07-19
老师,麻烦问下,在lua脚本中,并没有指明用的redis的第十个数据库,他是怎么找到数据的?还有如果redis设密码了 应该怎么连接?
写回答
2回答
-
吕相赫
2021-07-19
看我的 兄弟 齐全
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("8.140.67.103",6379)
cache:auth("root")
cache:select(10)
local item_model = cache:get("item_"..id)
if item_model == ngx.null or item_model == nil then
local resp = ngx.location.capture("/item/get?id="..id)
item_model = resp.body
end
ngx.say(item_model)
ngx.say("connect result:",ok)
012021-08-13 -
龙虾三少
2019-07-19
需要用redis对lua的api设置获得
022020-08-04
相似问题
服务端日志记录的问题
回答 1
redis连接不上
回答 1