{"action":"created","issue":{"url":"https://api.github.com/repos/redis/redis-rb/issues/524","repository_url":"https://api.github.com/repos/redis/redis-rb","labels_url":"https://api.github.com/repos/redis/redis-rb/issues/524/labels{/name}","comments_url":"https://api.github.com/repos/redis/redis-rb/issues/524/comments","events_url":"https://api.github.com/repos/redis/redis-rb/issues/524/events","html_url":"https://github.com/redis/redis-rb/issues/524","id":67016724,"number":524,"title":"Connections are not garbage collected","user":{"login":"robertgrimm","id":969670,"avatar_url":"https://avatars.githubusercontent.com/u/969670?v=3","gravatar_id":"","url":"https://api.github.com/users/robertgrimm","html_url":"https://github.com/robertgrimm","followers_url":"https://api.github.com/users/robertgrimm/followers","following_url":"https://api.github.com/users/robertgrimm/following{/other_user}","gists_url":"https://api.github.com/users/robertgrimm/gists{/gist_id}","starred_url":"https://api.github.com/users/robertgrimm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertgrimm/subscriptions","organizations_url":"https://api.github.com/users/robertgrimm/orgs","repos_url":"https://api.github.com/users/robertgrimm/repos","events_url":"https://api.github.com/users/robertgrimm/events{/privacy}","received_events_url":"https://api.github.com/users/robertgrimm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-08T00:00:27Z","updated_at":"2016-04-06T11:42:25Z","closed_at":null,"body":"I noticed the Redis class makes no attempt to automatically disconnect/quit its client connection when the Redis object is garbage collected and instead appears to force the application to manage that.  Is this by design?  While applications can of course keep track of this themselves and call Redis#quit when appropriate, it appears that the Redis class can be modified to do that automatically so applications don't have to worry about that and thus not leak Redis connections.\r\n\r\nFor example:\r\n\r\n```ruby\r\nclass Redis\r\n  def initialize(options={})\r\n     # existing initialize\r\n     # not sure if finalize should be called with @original_client or just client.\r\n     ObjectSpace.define_finalizer(self, self.class.finalize(@original_client))\r\n  end\r\n\r\n  def self.finalize(client)\r\n    proc { client.disconnect }\r\n  end\r\n\r\n  # rest of the class definition\r\nend\r\n```\r\n\r\nThis can be tested by doing something like\r\n\r\n```ruby\r\nredis = Redis.new\r\n# Would be nice if the gem natively supported \"client setname\"...\r\nredis.client.call([\"client\", \"setname\", \"test\"])\r\n# Run \"redis-cli client list | grep test\" or something similar to see the connection\r\nredis = nil\r\nGC.start\r\n# Run \"redis-cli client list | grep test\" again and see the connection is no longer there\r\n```\r\n\r\nAnother option would be add something like this to the Client class instead.  Thoughts?"},"comment":{"url":"https://api.github.com/repos/redis/redis-rb/issues/comments/206328949","html_url":"https://github.com/redis/redis-rb/issues/524#issuecomment-206328949","issue_url":"https://api.github.com/repos/redis/redis-rb/issues/524","id":206328949,"user":{"login":"badboy","id":2129,"avatar_url":"https://avatars.githubusercontent.com/u/2129?v=3","gravatar_id":"","url":"https://api.github.com/users/badboy","html_url":"https://github.com/badboy","followers_url":"https://api.github.com/users/badboy/followers","following_url":"https://api.github.com/users/badboy/following{/other_user}","gists_url":"https://api.github.com/users/badboy/gists{/gist_id}","starred_url":"https://api.github.com/users/badboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/badboy/subscriptions","organizations_url":"https://api.github.com/users/badboy/orgs","repos_url":"https://api.github.com/users/badboy/repos","events_url":"https://api.github.com/users/badboy/events{/privacy}","received_events_url":"https://api.github.com/users/badboy/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T11:42:25Z","updated_at":"2016-04-06T11:42:25Z","body":"Hey @BBCMarkMcDonnell.\r\nWe maitain redis-rb in our free time and may not face the same problems as heavy users. Looks like this issue just fell through. @hale's fix was never submitted as a PR, so we didn't really see that either.\r\nI now pulled it in (#603) and will wait for the CI to report back.\r\n\r\nThanks for bringing this up again."}}