如何解决redis连接运行时错误?

我正在尝试从我的openresty nginx服务器的nginx.conf文件中的lua脚本中访问redis。以下是lua脚本,我正在使用content_by_lua_file指令将其引用。

local redis = require "resty.redis"
local red = redis:new()
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
    ngx.log(ngx.ERR, "Redis连接失败:" .. err)
    return
end

我得到了运行时错误...尝试调用方法'connect'(空值)

这是怎么回事? 谢谢

点赞