jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 222 forks source link

Sentinels support #245

Closed codedigger-pl closed 7 years ago

codedigger-pl commented 7 years ago

Hi all

I have a question: how can I make it work with Redis cluster monitored by Sentinel? My current uwsgi script:

import os
os.environ.update(DJANGO_SETTINGS_MODULE='my_app.settings')

import gevent.socket
import redis.connection

from django.conf import settings
from redis import StrictRedis
from redis.sentinel import SentinelConnectionPool, Sentinel
from ws4redis import settings as private_settings
from ws4redis.uwsgi_runserver import uWSGIWebsocketServer

redis.connection.socket = gevent.socket

# remove any connection pool if specified
if 'connection_pool' in private_settings.WS4REDIS_CONNECTION:
    private_settings.pop('connection_pool')

sentinel = Sentinel(settings.REDIS_SENTINEL_URL, connection_timeout=5)
connection_pool = SentinelConnectionPool(settings.REDIS_NAME, sentinel)

connection = StrictRedis(connection_pool=connection_pool, **private_settings.WS4REDIS_CONNECTION)
application = uWSGIWebsocketServer(connection)

where REDIS_SENTINEL_URL is a list of tuples with sentinels, REDIS_NAME is a cluster name. It works fine when master is up all the time. When master goes down Sentinels recognize it and some slave is promoted to be a new master. But app is still using old master for connection.

How can I configure this?

jrief commented 7 years ago

Sorry, I never worked with Sentinel. Maybe you should ask at Stackoverflow, since this question seems not related to ws4redis.

codedigger-pl commented 7 years ago

Thank you. It looks like it is not possible (without hacks): Publisher uses own connection pool https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/publisher.py#L15 while Subscriber is using connection pool from uwsgi: https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/wsgi_server.py#L92 and https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/wsgi_server.py#L48