Created
November 17, 2013 06:45
-
-
Save proteneer/7510186 to your computer and use it in GitHub Desktop.
polling
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 | |
class Listener(threading.Thread): | |
def __init__(self, r, channels): | |
threading.Thread.__init__(self) | |
self.redis = r | |
self.pubsub = self.redis.pubsub() | |
self.pubsub.subscribe(channels) | |
def work(self, item): | |
print item['channel'], ":", item['data'] | |
def run(self): | |
for item in self.pubsub.listen(): | |
print item['data'] | |
if __name__ == "__main__": | |
r = redis.Redis() | |
r.config_set('notify-keyspace-events','Elx') | |
client = Listener(r, ['__keyevent@0__:expired', '__keyevent@0__:rpush']) | |
client.start() | |
print 'async! task running in bg now' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment