一个关于Redis 的疑问

问题

既然redis 是单线程的,那么为什么redis 客户端中要有连接池这种东西?

看到这个问题也有其他人问:

思考

我们知道连接池的一般好处,不用再每次使用时都重新建立连接。省去了开始的三次握手(和结尾的四次握手?)。但是如果我们使用一个常开的redis连接,同样没有新建连接的开销。

另外有人会提到阻塞的redis 命令(BRPOP),或者 SUBSCRIBE 或者watch,或者有实现时采用同步语义。如果不使用这些命令呢?

还有一个角度是,客户端本身是多线程的,如果用一个redis 连接,会竞争资源,加锁则会影响性能。

上面第三个链接的一个回答(似乎是Jedis 客户端的开发者):

In JRedis you have two options if you are using a front-end that
serves a lot of concurrent processes.
For low (concurrent) number of processes (threads), you can use
JRedisService. This connector maintains a pool of connections to
Redis and cycles through next available connection to serve service
requests.
For very high (concurrent) number of processes (thread count in the
thousands) – specially if you will be maintaining a constant load on
the connector – use the Pipeline with sync() semantics. Pipeline
uses a single connection, but has much higher throughput.

其他

连接池:
redis 连接池的使用
连接池的源码分析(python)

一个相关的问题:
为什么DB连接管理一般不采用IO多路复用?

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值