Skip to content

Instantly share code, notes, and snippets.

@r4vi
Created June 15, 2012 08:20
Show Gist options
  • Save r4vi/2935349 to your computer and use it in GitHub Desktop.
Save r4vi/2935349 to your computer and use it in GitHub Desktop.
redis-pubsub
import redis
import datetime
import time
def main():
r = redis.client.StrictRedis()
while True:
now = datetime.datetime.now()
print 'Sending {0}'.format(now)
r.publish('clock', now)
time.sleep(1)
if __name__ == '__main__':
main()
import redis
import threading
import time
def callback():
r = redis.client.StrictRedis()
sub = r.pubsub()
sub.subscribe('clock')
while True:
for m in sub.listen():
print m #'Recieved: {0}'.format(m['data'])
def main():
t = threading.Thread(target=callback)
t.setDaemon(True)
t.start()
while True:
print 'Waiting'
time.sleep(30)
if __name__ == '__main__':
main()
import redis
import threading
import time
import gevent
from gevent import monkey
monkey.patch_all()
def callback():
r = redis.client.StrictRedis()
sub = r.pubsub()
sub.subscribe('clock')
while True:
for m in sub.listen():
print m #'Recieved: {0}'.format(m['data'])
def zerg_rush(n):
for x in range(n):
t = threading.Thread(target=callback)
t.setDaemon(True)
t.start()
def main():
zerg_rush(1000)
while True:
print 'Waiting'
time.sleep(30)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment