我正在使用 Lua+nginx 和 OpenResty 包。但是当我尝试将 Lua 脚本与 Redis 连接时出现问题,我无法成功连接。我浏览了很多链接和博客,但最后总是失败。这是我正在尝试的代码片段。
server {
location /test {
content_by_lua '
local redis = require "resty.redis" // **Problem in code "Not able to require "resty.redis""**
local red = redis:new()
red:set_timeout(1000) -- 1 sec
-- or connect to a unix domain socket file listened
-- by a redis server:
-- local ok, err = red:connect("unix:/path/to/redis.sock")
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return
end
}
}