# 安装驱动
pip install redis
pip install python-redis
import redis
# 连接数据库
db = redis.Redis(host=127.0.0.1,port=6379,decode_responses=False)
# 如果要添加连接池则先创建连接池
pool=redis.ConnectionPool(decode_response=True)
db=redis.Redis(connection_pool=pool,host=127.0.0.1,port=6379)
# 又一种连接数据库的方式,方法和redis-cli 的使用命令基本一致
db=redis.StrictRedis()
# 数据操作
db.set("name","disen") # 添加string类型的key-value
print(db.get("name")) # 速去string类型的key
db.lpush("names","disen","jack","mack")
db.lrange("name",0,-1)
db.save()