先来解决start.bat闪退问题,直接在cmd运行redis-server.exe redis.windows.conf就可以了,虽然有点麻烦,然后加个pause也是可以的

pip install redis -i https://pypi.tuna.tsinghua.edu.cn/simple some-package下载安装redis-py模块

创建链接:

import redis
r = redis.Redis(
    host = "localhost",
    port = 6379,
    password = "123456",
    db = 0
)

创建连接池:

import redis
pool = redis。ConnectionPool{
    host = "localhost",
    port = 6379,
    password = "123456",
    db = 0
    max_connections = 20
)

 获取链接,不必关闭,回收时链接会自动归还到链接池

r = redis.Redis(
    connection_ppol = pool
)
......
del r

 redis-py模块用pipline(管道)的方式向redis服务器传递批处理命令和执行事务

pipline = con.pipline()
pipline.watch(...)
pipline.multi()
pipline.execute()
pipline.reset()//这个函数用来释放pipline

 

Posted on 2020-06-29 10:09  Schrodinger'sdoris  阅读(106)  评论(0编辑  收藏  举报