首页 > 其他 > 详细

redis原理

时间:2016-02-02 01:15:21      阅读:170      评论:0      收藏:0      [点我收藏+]

Client:

import tab,redis
s = redis.Redis(host=‘10.39.3.110‘)

chan = s.pubsub()
chan.subscribe(‘fm100‘)
chan.parse_response()

Servre:
import redis
p = redis.Redis(host=‘10.39.3.110‘)

p.publish(‘fm100‘,‘wo ai beijing tiananmen‘)

 

 

技术分享
 1 #!/usr/bin/env python
 2 #_*_ coding:utf-8 _*_
 3 
 4 import redis
 5 
 6 class RedisHelper:
 7 
 8     def __init__(self):
 9         self.__conn = redis.Redis(host=10.39.3.110)
10         self.chan_sub = fm87.7
11         self.chan_pub = fm104.5
12         
13     def get(self,key):
14         return self.__conn.get(key)
15 
16     def set(self,key,value):
17         self.__conn.set(key,value)
18 
19     def public(self,msg):
20         self.__conn.publish(self.chan_pub, msg)
21         return True
22 
23     def subscribe(self):
24         pub = self.__conn.pubsub()
25         pub.subscribe(self.chan_sub)
26         pub.parse_response()
27         return pub
28 
29 if __name__ == __main__:
30     t = RedisHelper()
31     t.public(test)
View Code

 

redis原理

原文:http://www.cnblogs.com/liyongsan/p/5176634.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!