Example 001,
Connect to Redis through Strictredis mode and call the GET command to read a string of value.
#!/usr/bin/python#!coding:utf-8ImportRedisif __name__=="__main__": Try: R=redis. Strictredis (host='192.168.80.128', port=6379,db=0)#Strictredis Connect the Redis server in strict mode. #1, do not realize slect #2. Redis's del command instead of the Delete command (because del is also a keyword in python) Print(R.get ('slogan'). Decode ('Utf-8'))#the Received object is of type byte exceptException as err:Print(ERR)
By default, each Redis instance manages itself with a connection pool that is used to connect to the Redis-server side, which means that if there are multiple Redis objects in the program, there will be multiple connection pools, which is obviously not available.
So Redis also provides a way to share connection pooling.
Example 002,
Multiple Redis objects share a single connection pool.
#!/usr/bin/python#!coding:utf-8ImportRedisif __name__=="__main__": Try: Conn_pool=redis. ConnectionPool (host='192.168.80.128', port=6379,db=0) R=redis. Redis (connection_pool=Conn_pool)#R=redis. Strictredis (host= ' 192.168.80.128 ', port=6379,db=0) #Strictredis Connect the Redis server in strict mode. #1, do not realize slect #2. Redis's del command instead of the Delete command (because del is also a keyword in python) Print(R.get ('slogan'). Decode ('Utf-8'))#the Received object is of type byte exceptException as err:Print(ERR)
Python connection redis002