{"id":22677917,"url":"https://github.com/mohammedamarnah/redis-pool","last_synced_at":"2026-03-04T08:32:29.680Z","repository":{"id":54565887,"uuid":"295026240","full_name":"mohammedamarnah/redis-pool","owner":"mohammedamarnah","description":"A simple Redis dynamic-sized connection pool.","archived":false,"fork":false,"pushed_at":"2021-11-30T21:29:13.000Z","size":29,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-10T23:37:32.509Z","etag":null,"topics":["connection-pool","rails","redis","redis-client","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/redis_dynamic/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohammedamarnah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-12T21:06:27.000Z","updated_at":"2022-03-10T22:08:09.000Z","dependencies_parsed_at":"2022-08-13T20:00:19.279Z","dependency_job_id":null,"html_url":"https://github.com/mohammedamarnah/redis-pool","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mohammedamarnah/redis-pool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammedamarnah%2Fredis-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammedamarnah%2Fredis-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammedamarnah%2Fredis-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammedamarnah%2Fredis-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohammedamarnah","download_url":"https://codeload.github.com/mohammedamarnah/redis-pool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammedamarnah%2Fredis-pool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278887344,"owners_count":26063169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connection-pool","rails","redis","redis-client","ruby"],"created_at":"2024-12-09T18:13:07.082Z","updated_at":"2025-10-08T17:10:51.784Z","avatar_url":"https://github.com/mohammedamarnah.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redis-pool [![Build Status][gh-actions-image]][gh-actions-link]\nA simple redis dynamic-sized connection pool.\nThere are several implementations of connection pools in ruby, but none of them supports dynamic sizes. Any connection pool would open a static amount of connections and would never kill them even if they are idle and not being used.\nWhat if you need a large number of connections in very rare cases, but normally will not use more than a couple of ones? This pool is a great choice!\n\n## Why redis-pool?\nImagine that you have an application that in very rare cases (let's say X minutes-hours per day) gets a huge amount of traffic that needs a high number of connections, but all the other times you would need only a couple of ones open. Having a big amount of connections open (while the connections are idle) is a memory consuming operations.\n\nI took inspiration from where I work: we have **N servers**, each server instantiates **M puma instances** (ruby on rails server) and each instance fires up **K redis connections** on boot-up. This makes the total open connections **N x M x K redis connections**! Imagine adding one instance? or one server!\n\nThis gem was implemented heavily based on two main implementations:\n\n1- [mperham's connection_pool](https://github.com/mperham/connection_pool)\n\n2- [rails' ActiveRecord Connection Pool](https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html)\n\nThe former provides an efficient connection pool implementation that creates connections lazily (only upon actual need of that connection), but keeps the connections alive once they're opened. The latter provides a connection pool implementation (specific for rails' database interfaces) that supports a dynamic size of the connection pool. This gem is a combination of the perks of the two, combines the lazy evaluation with idle-connection killing support.\n\nHere's the difference between normal connection-pools and redis-pool shown in a simple graph:\n![difference](https://user-images.githubusercontent.com/11768502/106142062-ae693680-6179-11eb-9b40-4fa32d641904.jpeg)\n## Installation\nInstall the gem using the `gem install` command or add it to your Gemfile and run `bundle install`\n```\n# bundler install: add this to your Gemfile\ngem 'redis_dynamic'\n\n# manual install\ngem install redis_dynamic\n```\n## Usage\nEasily create a pool:\n```ruby\npool = RedisPool.new()\n# You can set the maximum size of the pool\npool = RedisPool.new(max_size: 10)\n```\nYou can set several options for the pool. i.e:\n`connection_timeout`: raises a TimeoutError after `connection_timeout` of trying to get hold of a connection.\n`reaping_frequency`: checks every `reaping_frequency` for any idle connections to kill.\n`idle_timeout`: kills any connection that has been idle for `idle_timeout`.\n\nUse the connections using `with_conn`:\n```ruby\npool = RedisPool.new(max_size: 10, connection_timeout: 5, idle_timeout: 300)\npool.with_conn { |conn|\n    conn.get('hello')\n}\n```\nYou can override the default `connection_timeout` using `with_conn(timeout)`:\n```ruby\npool = RedisPool.new()\npool.with_conn(5) { |conn|\n    conn.get('hello')\n}\n```\n## Pool Stats\nYou can also get stats about all connections that are currently alive in the pool. Stats include the id of each connection, when it was created `alive_since` and when it was last used at `last_used_at`.\n```ruby\npool = RedisPool.new()\npool.with_conn { |conn| conn.get('hello') }\npool.stats # {:available_to_create=\u003e4, :total_available=\u003e5, :connections_stats=\u003e[{:id=\u003e0, :alive_since=\u003e2021-01-25 13:41:12.749529574 UTC, :last_used_at=\u003e2021-01-25 13:41:12.749532585 UTC}]}\n```\n## Redis Configuration\nYou can specify custom redis configuration when initializing the pool.\n```ruby\npool = RedisPool.new(redis_config: {host: 'localhost', port: 5000, db: 10})\n```\n[gh-actions-image]: https://github.com/mohammedamarnah/redis-pool/workflows/Ruby/badge.svg\n[gh-actions-link]:  https://github.com/mohammedamarnah/redis-pool/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammedamarnah%2Fredis-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohammedamarnah%2Fredis-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammedamarnah%2Fredis-pool/lists"}