I have a real-time web application when a client receives updates from several Redis PubSub channels built using gevent-socketio and redis-py.
I am watching views.py, l.26 in django-tictactoe . It generates new greens when the client sends a message to subscribe to the channel. Then, the green subscribes to the Redis PubSub channel and blocks until a message is received.
class GameNamespace(BaseNamespace):
def listener(self, chan):
red = redis.StrictRedis(REDIS_HOST)
red = red.pubsub()
red.subscribe(chan)
print 'subscribed on chan ', chan
while True:
for i in red.listen():
self.send({'message': i}, json=True)
def recv_message(self, message):
action, pk = message.split(':')
if action == 'subscribe':
Greenlet.spawn(self.listener, pk)
In my opinion, it’s not possible to add subscriptions without creating new Greenlets or without subscribing.
How would you efficiently handle frequent subscriptions and unsubscribes?
: , , MMO HTML5 2D-. - . , , , (, Google Maps).
, , / , , . , , , .
() . , SUBSCRIBE UNSUBSCRIBE , "O(N) where N is the number of clients already subscribed to a channel". , .
, Python Redis PubSub . red.listen() , , . Greenlet Redis , , , .