2

I am using Lua+nginx with OpenResty bundle. But problem comes when I try to connect Lua script with Redis, I'm not able to make successful connection. I have gone through a lot of links and blogs, But in the end it always fails. This is the snippet of code which I am trying.

   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
  }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Rana Pratap Singh
  • 867
  • 12
  • 18

1 Answers1

0

Assuming "not able to require" means you are getting module 'resty.redis' not found message with a list of paths, the error indicates that you are missing the module. You need to check the paths that are listed and make sure that resty/redis.lua is in one of those folders. You will find that file in lua-resty-redis-<version> folder in your OpenResty installation.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56