繁体   English   中英

如何在Redis中使用Lua?

[英]How to use Lua with Redis?

我正在将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
  }
}

假设“无法要求”表示您正在获取module 'resty.redis' not found消息,其中包含路径列表,则该错误表明您缺少该模块。 您需要检查列出的路径,并确保resty/redis.lua在这些文件夹之一中。 您将在OpenResty安装的lua-resty-redis-<version>文件夹中找到该文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM