Operating mode
R = Redis. Redis (host= "192.168.80.20", port=6379) R.set ("name", "Jiachen") Print (R.get ("name"))
Connection pool
Pool = Redis. ConnectionPool (host= "192.168.80.20", port=6379) R = Redis. Redis (Connection_pool=pool) r.set ("name", "Jiachen") Print (R.get ("name"))
String manipulation
Hash operation
List operation
Set operation
Other operations
Http://www.redis.cn/commands.html
Pipeline
Import Redisimport Timepool = Redis. ConnectionPool (host= ' 192.168.80.20 ', port=6379) R = Redis. Redis (connection_pool=pool) # pipe = R.pipeline (transaction=false) pipe = R.pipeline (transaction=true) pipe.set (' name ' , ' Wupeiqi ') time.sleep (() Pipe.set (' Role ', ' SB ') Pipe.execute ()
Subscribe/Publish
Import Redisclass redishelper:def __init__ (self): Self.__conn = Redis. Redis (host= ' 10.211.55.4 ') self.chan_sub = ' fm104.5 ' self.chan_pub = ' fm104.5 ' def public (self, msg): Self.__conn.publish (Self.chan_pub, msg) return True def subscribe (self): pub = Self.__conn.pubsub () Pub.subscribe (self.chan_sub) pub.parse_response () return pub
Subscription
From Monitor. Redishelper import Redishelper obj = Redishelper () redis_sub = Obj.subscribe () while true:msg= Redis_sub.parse_response () Print MSG
Release
From Monitor. Redishelper import Redishelper obj = Redishelper () obj.public (' Hello ')
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1912399
The path of Python 49-redis