-
Notifications
You must be signed in to change notification settings - Fork 3
Connection Pools
Paul Bergeron edited this page May 2, 2013
·
2 revisions
Sometimes you're connecting to a remote reasource using a driver that doesn't support connection pooling, which will limit the amount of strain your application puts on that reasource, and allow for reuse of existing connections instead of increasing overhead by reconnecting each time. Connection Pool support in Rhod is provided by the connection_pool gem.
require 'rhod'
require 'redis'
require 'connection_pool'
Rhod.create_profile(:redis,
pool: ConnectionPool.new(size: 3, timeout: 5) { Redis.new }
)
Rhod.with_redis {|redis| redis.set("foo", "bar") }
# => "OK"
The connection is always the first argument passed into the block, the other arguments are passed in their original order after.
key = "foo"
value = "bar"
Rhod.with_redis(key, value) {|redis, k, v| redis.set(k, v) }