Created
June 15, 2012 08:20
-
-
Save r4vi/2935349 to your computer and use it in GitHub Desktop.
redis-pubsub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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