Skip to content

Instantly share code, notes, and snippets.

@m4scosta
Created January 5, 2017 01:41
Show Gist options
  • Save m4scosta/529333c166a90338786eb23a626f7936 to your computer and use it in GitHub Desktop.
Save m4scosta/529333c166a90338786eb23a626f7936 to your computer and use it in GitHub Desktop.
Redis pubsub python
import redis
import time
def message_handler(message):
print(time.time() - float(message['data']))
def run():
r = redis.StrictRedis()
p = r.pubsub()
p.subscribe(**{'event': message_handler})
thread = p.run_in_thread(sleep_time=0.001)
try:
thread.join()
except:
thread.stop()
if __name__ == '__main__':
run()
import redis
import sys
import time
def run():
r = redis.StrictRedis()
for i in range(1, 1000):
r.publish('event', time.time())
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment