【问题标题】:How to use Lua with Redis?如何在 Redis 中使用 Lua?
【发布时间】:2015-04-06 10:57:50
【问题描述】:

我正在使用 Lua+nginx 和 OpenResty 包。但是当我尝试将 Lua 脚本与 Redis 连接时出现问题,我无法成功连接。我浏览了很多链接和博客,但最后总是失败。这是我正在尝试的代码的 sn-p。

   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
  }
}

【问题讨论】:

  • /usr/local/openresty/lualib/resty/redis.lua可以查到吗?

标签: nginx lua openresty


【解决方案1】:

假设“无法要求”意味着您收到带有路径列表的 module 'resty.redis' not found 消息,该错误表明您缺少该模块。您需要检查列出的路径并确保 resty/redis.lua 位于这些文件夹之一中。您将在 OpenResty 安装的 lua-resty-redis-<version> 文件夹中找到该文件。

【讨论】:

    猜你喜欢
    • 2014-02-17
    • 2021-06-19
    • 2014-02-10
    • 2021-07-30
    • 2016-08-10
    • 2020-07-15
    • 2018-05-11
    • 1970-01-01
    • 2013-08-28
    相关资源
    最近更新 更多