Skip to content

Client pooling 1.x.x

Alexandre Curreli edited this page Jul 28, 2014 · 1 revision

The pool is thread-safe but borrowed clients are not!

import scredis._

// Initializes a pool with default parameters
val pool = ClientPool()()

// Borrows a client from the pool
val client = pool.borrowClient()
try {
  client.set("STR", "Hello World!")
} finally {
  // Don't forget to always return a borrowed client
  pool.returnClient(client)
}

// Preferred method: automatically borrows and returns a client
pool.withClient { client =>
  client.set("STR", "Hello World!")
}