redis实现发布订阅

订阅者

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 import redis
 4 
 5 r = redis.Redis(host='192.168.11.119')
 6 pub = r.pubsub()
 7 pub.subscribe('fm9999')
 8 while True:
 9     msg= pub.parse_response()
10     print(msg)

发布者

1 #!/usr/bin/env python
2 # -*- coding:utf-8 -*-
3 import redis
4 
5 r = redis.Redis(host='192.168.11.119')
6 r.publish('fm9999', 'sb')

 

posted @ 2017-04-03 09:36  失落的黎明  阅读(198)  评论(0编辑  收藏  举报