title: Connection in Redis and Lua
body: <p>This is my config:</p>
  
  <pre><code>local rc = require("resty.redis.connector").new({
                  connect_timeout = 50,
                  read_timeout = 5000,
                  keepalive_timeout = 30000
              })
  
              local redis, err1 = rc:connect({
                  url = "redis://127.0.0.1:6379",
              })
  
              if not redis then
                  ngx.say( err1)    
              else
                  ngx.say('connection fine')    
              end
  
              local ok, err = rc:set_keepalive(redis)  
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <blockquote>
    <p>[error] 4044#0: *1068056 attempt to send data on a closed socket:
    u:00007F2BABA05D48, c:0000000000000000, ft:0 eof:0, client: MY IP,
    server: , request: "GET /foo HTTP/1.1", host: "SERVER IP"</p>
  </blockquote>
  
  <p>When I disable keepalive setting, get this error:</p>
  
  <blockquote>
    <p>[error] 4147#0: *1089971 lua tcp socket connect timed out, when
    connecting to 127.0.0.1:6379,</p>
  </blockquote>
  
  <p>When I comment out the line related to rc:set_keepalive it works on single requests and crashes on 100 requests.</p>
  
  <p>What is the best practices for connecting to Redis in Lua under huge requests?</p>