0

I want to create connection to Tarantool database in init_by_lua_block or init_worker_by_lua_block and then use that created connection in each content_by_lua_block:

init_by_lua_block {
    local tnt = require 'resty.tarantool'

    local tar, err = tnt:new({
        host = '127.0.0.1',
        port = 3312,
        user = 'user',
        password = 'password',
        socket_timeout = 2000
    })

    local res, err = tar:connect()
}

But cosocket api is disabled in directives init_*_by_lua*. How I can create connection one time instead of creating connections for each request?

zodiac
  • 353
  • 3
  • 18

1 Answers1

0

Use https://github.com/perusio/lua-resty-tarantool#set_keepalive

Makes the connection created get pushed to a connection pool so that the connection is kept alive across multiple requests.

Alexander Altshuler
  • 2,930
  • 1
  • 17
  • 27