使用Python连接redis(redis作MQ使用)
1、安装redis Python客户端
easy_install.exe redis
2、启动redis
sudo redis-server
3、编写接收端
import redis
rc = redis.Redis(host='mt.ematchina.com')
ps = rc.pubsub()
ps.subscribe(['foo', 'bar'])
#rc.publish('foo', 'hello world')
for item in ps.listen():
if item['type'] == 'message':
# print item['channel']
print item['data']
4、编写发送端
import redis
rc = redis.Redis(host='mt.ematchina.com')
ps = rc.pubsub()
ps.subscribe(['foo', 'bar'])
rc.publish('foo', 'hello world')