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

Django-socketio with Redis.

Open Marcolac opened this issue 12 years ago • 0 comments

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.

Marcolac avatar Jan 28 '13 17:01 Marcolac