Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
redis module installation: pip3 install redisor easy_install redisor with the installation source.
First, the connection
There are two connections, one is connected using a general manner, the other is to use the connection pool, the latter is recommended.
1, the general connection
redis-py provides two classes for implementing Redis Redis and StrictRedis commands StrictRedis for implementing most of the official orders, and the use of official syntax and commands, Redis is StrictRedis subclass for backward compatibility with older versions of redis-py.
import redis
r = redis.Redis(host='106.12.115.136', port=6379)
print(r.set('flag', 1))
print(r.get('flag'))
1, connection pool connection (recommended)
import redis
pool = redis.ConnectionPool(host='106.12.115.136', port=6379)
r = redis.Redis(connection_pool=pool)
print(r.set('flag', 1))
print(r.get('flag'))