No commit activity in last 3 years
No release in over 3 years
A useful connection manager
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.16
~> 5.0
~> 10.0
 Project Readme

ConnectionManager

Build Status Gem Version

A gem to manage your persistent connections.

Usage

Create a thread-safe connection manager:

$manager = ConnectionManager.new(timeout: 5)

Push your connections at any time:

$manager.push("redis") { Redis.new }

And use them according to your needs:

$manager.with("redis") do |redis|
  redis.get("mykey")
end

A metadata store per connection is also available allowing you to create custom behavior:

Thread.new do
  $manager.with("redis") do |redis, metadata|
    metadata[:last_used_at] = Time.now
    redis.get("mykey")
  end
end

Thread.new do
  metadata = $manager.metadata("redis")
  $manager.reset("redis") if metadata[:last_used_at] < 1.hour.ago
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/spuyet/connection_manager.

License

The gem is available as open source under the terms of the MIT License.

Author

Sébastien Puyet (@spuyet): sebastien@puyet.fr