Skip to content

Commit

Permalink
one redis pool instance
Browse files Browse the repository at this point in the history
  • Loading branch information
uuip committed Feb 8, 2022
1 parent 1140174 commit 63cf0f5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions celery/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def __init__(self, main=None, loader=None, backend=None,

self.on_init()
_register_app(self)
self.redis_backend = None

def _get_default_loader(self):
# the --loader command-line argument sets the environment variable.
Expand Down Expand Up @@ -955,6 +956,11 @@ def _get_backend(self):
backend, url = backends.by_url(
self.backend_cls or self.conf.result_backend,
self.loader)
# redis-py always use independent connection for every command, one pool instance is enough
if url.startswith('redis'):
if not self.redis_backend:
self.redis_backend=backend(app=self, url=url)
return self.redis_backend
return backend(app=self, url=url)

def _finalize_pending_conf(self):
Expand Down

0 comments on commit 63cf0f5

Please sign in to comment.