1.简单连接
import redis conn = redis.Redis(host='207.148.120.229', port=6379) conn.set('foo', 'Bar') print(conn.get('foo')) a = input('按任意键结束')
2.使用连接池
import redis pool = redis.ConnectionPool(host='207.148.120.229',port=6379) conn = redis.Redis(connection_pool=pool) conn.set('key', 'Hello World') print(conn.get('key')) a = input('按任意键结束')