django-redis icon indicating copy to clipboard operation
django-redis copied to clipboard

Use Existing Connection Pool

Open ZuSe opened this issue 3 years ago • 8 comments

Hi guys,

i wanted to ask if there is the option to use an existing connection pool? I have redis-py already in place for huey and would love to pass in my SentinelConnectionPool to django-redis as well. So I need to define it once and can share it across all redis dependend clients.

e.g. this is how it looks for huey


 'connection': {
        'connection_pool': SentinelConnectionPool(service_name="mymaster",
                                         sentinel_manager=sentinel.Sentinel([("localhost",26379)],
                                                                            password="XXXXXXX",
                                                                            socket_timeout=10,
                                                                            sentinel_kwargs={"password": "XXXXX"})
                                         ),
    },

ZuSe avatar May 05 '21 15:05 ZuSe

IIRC that's not "exactly" supported by default, but making a trivial connection factory would be the way to do it https://github.com/jazzband/django-redis#customize-connection-factory

terencehonles avatar May 05 '21 22:05 terencehonles

Hello @ZuSe!

Maybe the new feature added by @terencehonles supporting sentinel is what you are looking for?

WisdomPill avatar May 06 '21 08:05 WisdomPill

I guess I didn't quite think of that :sweat_smile: . If the question is to use a redis sentinel I did contribute a connection factory recently that would likely work. If you did indeed want to use an existing pool or connection you'd need to use the connection factory as I suggested since the connection factory will create new connections and will need to be passed the same arguments you use for huey.

terencehonles avatar May 06 '21 14:05 terencehonles

@ZuSe has your question been answered or you are looking for something else?

Just asking so that we could close this issue.

WisdomPill avatar May 22 '21 06:05 WisdomPill

Might it make sense to enable a stale bot to auto close issues like this? I'm not sure if we've been given permissions to install anything like that though :thinking: since I think we're still waiting on a number of things for "full" jazzband membership and I don't know if the org is set up to allow that every :confused:

terencehonles avatar May 22 '21 19:05 terencehonles

@ZuSe has your question been answered or you are looking for something else?

Just asking so that we could close this issue.

Hi @WisdomPill

yes, it's kinda answered. Now, the question would be more how you you guys think about providing Connection"-Pools from redis.py right away, but I think that can be discussed in another issue

@terencehonles Could you maybe share ur connection factory? :)

Best

ZuSe avatar May 22 '21 21:05 ZuSe

@WisdomPill is referring to the one that was merged in with https://github.com/jazzband/django-redis/pull/460

terencehonles avatar May 22 '21 22:05 terencehonles

Hey @ZuSe,

you can get ConnectionPool already like it is shown in the README here

WisdomPill avatar May 27 '21 15:05 WisdomPill