Redis installation uses1. Download Redis:Http://redis.io/download2, decompression installation: #tar zxfredis-3.0.6.tar.gz #make
3. Start #cd/usr/local/src/redis-3.0.6 #Src/redis-server &
4. Check
5. Login #src/redis-cli
6. Common Commands
set name ' YANGMV ' Save Data
Get name Fetch Data
set name ' NB ' EX to save data, and sets the timeout time to 10 seconds
lpush name_list ' Shanghai ' Beijing ' Save a list, reverse
R
push name_list ' Shanghai ' Beijing ' rpush list positive order
lrange name_list 0 2 according to the subscript to take the value0-1 View All
Save
save data to hard disk
Keys * View All data
python operation Redis
Installing the Python redis module
wget Https://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gztar Zxfredis-2.9.1.tar.gzcdredis-2.9.1python Setup.pyinstall
access List
Connection pool:Redis-py uses connection pool to manage all connections to a Redis server, avoiding the overhead of each establishment and release of the connection. By default, each Redis instance maintains its own pool of connections. You can create a connection pool directly, and then as a parameter Redis, you can implement multiple Redis instances to share a single connection pool.
Redis Subscription Publishing Features
Server side:
Import Redisclass redishelper: def __init__ (self): self.__conn = Redis. Redis (host= ' 127.0.0.1 ') self.chan_sub = ' fm87.7 ' def subscribe (self): pub = Self.__conn.pubsub () Pub.subscribe (self.chan_sub) pub.parse_response () return pubif __name__ = = ' __main__ ': r = Redishelper () recv = R.subscribe () #订阅fm87.7 Channel while True: #循环监听接收 print recv.parse_response () # Listen to the channel and receive messages from the client
Client side:
Import Redisclass redishelper: def __init__ (self): self.__conn = Redis. Redis (host= ' 127.0.0.1 ') self.chan_pub = ' fm87.7 ' def Public (self,msg): #发布内容到fm87. Channel 7 self.__ Conn.publish (Self.chan_pub, msg) return trueif __name__ = = ' __main__ ': t = redishelper () t.public (' Test ') #test为发布的内容
Server subscribes to fm87.7 messages
after executing the Python client.py publish message, the server gets the subscribed message
Redis Subscription Publishing Features