Redis py:何时使用连接池? [英] Redis py: when to use connection pool?

查看:33
本文介绍了Redis py:何时使用连接池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pool = redis.ConnectionPool(host='10.0.0.1', port=6379, db=0)
r = redis.Redis(connection_pool=pool)

对比

r = redis.Redis(host='10.0.0.1', port=6379, db=0)

这两个很好用.

使用连接池背后的想法是什么?你什么时候使用它?

Whats the idea behind using connection pool? When would you use it?

推荐答案

来自 redis-py 文档:

在幕后,redis-py 使用连接池来管理与 Redis 服务器的连接.默认情况下,您创建的每个 Redis 实例将依次创建自己的连接池.您可以通过将已创建的连接池实例传递给 Redis 类的 connection_pool 参数来覆盖此行为并使用现有连接池.您可以选择这样做以实现客户端分片或对连接的管理方式进行更精细的控制.

Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool instance to the connection_pool argument of the Redis class. You may choose to do this in order to implement client side sharding or have finer grain control of how connections are managed.

所以,通常这不是您需要自己处理的事情,如果您这样做了,那么您就知道了!

So, normally this is not something you need to handle yourself, and if you do, then you know!

这篇关于Redis py:何时使用连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆