ledgetech / lua-resty-redis-connector

Connection utilities for lua-resty-redis
234 stars 71 forks source link

Question: Redis Connection pool with Sentinel #6

Closed rohitjoshi closed 8 years ago

rohitjoshi commented 8 years ago

@pintsized thanks for adding support for the sentinel. If I want to use the redis slaves for the read and master for the write

  1. How connection pool is managed?
  2. When a slave becomes master, does it get updated?
pintsized commented 8 years ago

The connection pool isn't aware of Redis roles, it's just a tcp socket connection pool. So if Sentinel tells you that host x is master, then you can rely this, regardless of whether it has always been master or was formerly a slave. Just because Redis has promoted the role, doesn't mean that client connections behave any differently.

To put it another way, you can connect to a slave and then put that connection in the keepalive pool. Sentinel might then promote that slave to master. If you connect to a master, and receive the same host / port as the slave you used previously, the connection may be reused from the pool. But you can safely treat this connection as a master because Redis has promoted it.

Does that answer your question?

rohitjoshi commented 8 years ago

Thanks @pintsized