推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
myyou
V2EX  ›  Python

python redis 建立连接,操作完成后需要关闭连接吗?

  •  
  •   myyou · Feb 24, 2016 · 18028 views
    This topic created in 3763 days ago, the information mentioned may be changed or developed.

    如建立连接 r = redis.Redis(host='127.0.0.1',port=6379,db=0)
    操作完成后需要关闭连接吗?
    如果需要,怎样关闭?

    6 replies    2016-02-25 13:21:07 +08:00
    knightdf
        1
    knightdf  
       Feb 24, 2016   ❤️ 1
    不需要
    DEMONHUNTER
        2
    DEMONHUNTER  
       Feb 24, 2016   ❤️ 1
    redis 连接对象不在了,连接就断了。
    ahxxm
        3
    ahxxm  
       Feb 24, 2016   ❤️ 1
    hiredis 不知道

    https://github.com/andymccurdy/redis-py/blob/master/redis/client.py#L2136 这个看起来 Redis 删除时会自动 reset , StrictRedis 不会
    Aydon0
        4
    Aydon0  
       Feb 24, 2016 via Android   ❤️ 1
    不需要关闭连接。
    fatpa
        5
    fatpa  
       Feb 25, 2016   ❤️ 1
    不需要,而且如果是用 StrictRedis 的方式,还会帮你把连接丢回连接池里面
    myyou
        6
    myyou  
    OP
       Feb 25, 2016
    哦,知道了谢谢各位的回答。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5691 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 01:50 · PVG 09:50 · LAX 18:50 · JFK 21:50
    ♥ Do have faith in what you're doing.