1. Install Redis,pyredis First
sudo pip install Redis
sudo pip install Python-redis
2. Example:
Import Redis >>> r = Redis. Redis (host = ' localhost ', port = 6379, db = 0) >>> R. Set (' Guo ', ' Shuai ') True >>> R. Get (' Guo ') ' Shuai ' >>> R [' Guo '] ' Shuai ' >>> R. Keys () [' Guo '] >>> R. Dbsize () #当前数据库包含多少条数据 1L >>> R. Delete (' Guo ') 1 >>> R. Save () #执行 a checkpoint to write data back to disk. Blocking True >>> R while saving. Get (' Guo '); >>> R. Flushdb () #清空r中的所有数据 True
3. Pipeline:
Server and client is the use of socket to send TCP messages to communicate, using pipeline way from the client packaging multiple commands together, do not need to wait for a single command response to return, The Redis server, after processing more than one command, will package the processing results of multiple commands back to the client. This saves time wasting on network latency, pipeline way to pack and send commands,