Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django-socketio with Redis. #43

Open
Marcolac opened this issue Jan 28, 2013 · 0 comments
Open

Django-socketio with Redis. #43

Marcolac opened this issue Jan 28, 2013 · 0 comments

Comments

@Marcolac
Copy link

Hi,

I'm trying to implement Redis with django-socketio in a chat. So here is what I did:

def listener(self):
    r = redis.StrictRedis()
    r = r.pubsub()

    r.subscribe('chat')

    for m in r.listen():
        message = m['data']
        socket.send_and_broadcast_channel(message)

@events.on_message()
def messages(request, socket, context, message):
    r = redis.Redis()
    r.publish('chat', message)

But in order redis to work with gevent, we have to start a Greenlet when the user subscribes.
So we need to add something like that:

def on_subscribe(self, *args, **kwargs):
        self.spawn(self.listener)

I tried to do that with django-socketio but I didn't figured how to do it.

Would you have any idea on how can I do the equivalent with django-socketio?

Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant