Some of their own initial attempts, there is no place to be wrong, thank you ~
Download the Redis library used by Python:
HTTPS://pypi.python.org/packages/source/r/redis/redis-2.10.3.tar.gz
Install after decompression:
Python setup.py Install
Operation Code:
#-*-coding:cp936-*-ImportRedis#Initializing the connection configuration#here is an explanation of the following db parameter:#db Incoming shaping value, the range is limited to the server configuration. #The default Redis server is configured as DATABASES=16, which is the value between DB 0~15. #data between different db is independent of each other, so in multi-user cases, DB can be specified to avoid conflicts caused by data rewriting. Redis_client = Redis. Redis (host=' 127.0.0.1', port=6379, Db=0, password='redis123$', socket_timeout=3)#operating Redis#It should be noted that the Python-redis should be in the form of short connections, ShikaTry: #Verify that you are logged on correctly Printredis_client.ping ()#gets the number of the current key Printredis_client.dbsize ()#Get all keys PrintRedis_client.keys ()#set the key valueRedis_client.set ('Host','@localhost') #See if the key exists PrintRedis_client.exists ('Host') #View Key data Types PrintRedis_client.type ('Host') #Reading key Values PrintRedis_client.get ('Host') #change the name of the keyRedis_client.rename ('Host','Foo') #Read key value 2 Printredis_client['Foo'] #Delete keyRedis_client.delete ('Foo') #Remove all key valuesredis_client.flushdb ()#Save ChangesRedis_client.save ()#connection error, usually caused by an incorrect address or port numberexceptRedis. Connectionerror, E:Print 'Connectionerror:%s'%E.message#response error, incorrect database name or password, or other error causedexceptRedis. Responseerror, E:Print 'Responseerror:%s'% E.message