Created
January 5, 2017 01:41
-
-
Save m4scosta/529333c166a90338786eb23a626f7936 to your computer and use it in GitHub Desktop.
Redis pubsub python
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 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() |
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 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