No description
Find a file
2022-01-20 11:51:05 +01:00
src Add proper error handling, bump Nim version 2022-01-20 11:51:05 +01:00
README.md Make pool public, fix fd leak, add await template 2020-06-01 01:12:32 +02:00
redpool.nimble Add proper error handling, bump Nim version 2022-01-20 11:51:05 +01:00

redpool

Simple Redis connection pool.

The timeout argument allows connections to be reused after a given time, in case they don't get released properly. The maxConn argument sets a soft limit, which destroys connection objects when released if the limit has been reached. The withAcquire template can be used to automatically acquire and release a connection, but note that with Nim versions below 1.3.1, the acquire call is waitFor'd since async wasn't allowed inside templates and macros before that.

Usage

import asyncdispatch, redis, redpool

proc main {.async.} =
  let pool = await newRedisPool(5, timeout=4, maxConns=7)

  # manual acquire
  let conn = await pool.acquire()
  echo await conn.ping()
  await pool.release(conn)

  # acquire template
  pool.withAcquire(conn2):
    echo await conn2.ping()