Python Redis 连接与操作

前言

以前写过一篇,后来大整理的时候删掉了.不过好久没用Redis,近期业务需求重新拾起来

变更记录

# 19.3.26 起笔

# 19.3.26 新增 连接redis

正文

介绍

redis的介绍这里就不再赘述,这里给出官网

https://redis.io/

百度百科

https://baike.baidu.com/item/Redis

安装

pip3 install redis

连接redis

redis一般是部署在服务器上/又或者是在腾讯云等服务商购买服务.一般来说redis都是带密码的.

我们在使用redis的第一步就是连接redis

一般来说我们使用连接池能更快速地连接到redis

import redis

# redispool配置(创建连接池)
pool = redis.ConnectionPool(
    host='xx.xx.xx.xx',  # host
    port=6390,  # port
    db=0,  # db
    password='xxxxxxxxxxxxx'  # pwd
    ) 
# redis(从连接池中生成一个链接)
r = redis.Redis(connection_pool=pool)

 pass

猜你喜欢

转载自www.cnblogs.com/chnmig/p/10598945.html