Skip to content

Commit 18b33e4

Browse files
Also send reads to the master when load_from_slaves is '2'.
1 parent b78555c commit 18b33e4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Cm/Cache/Backend/Redis.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ public function __construct($options = array())
210210
if ( ! empty($options['load_from_slaves'])) {
211211
$slaves = $sentinel->getSlaveClients($sentinelMaster);
212212
if ($slaves) {
213+
if ($options['load_from_slaves'] == 2) {
214+
array_push($slaves, $this->_redis); // Also send reads to the master
215+
}
213216
if ($slaveSelect) {
214217
$slave = $slaveSelect($slaves, $this->_redis);
215218
} else {
216219
$slaveKey = array_rand($slaves, 1);
217220
$slave = $slaves[$slaveKey]; /* @var $slave Credis_Client */
218221
}
219-
if ($slave instanceof Credis_Client) {
222+
if ($slave instanceof Credis_Client && $slave != $this->_redis) {
220223
try {
221224
$this->_applyClientOptions($slave, TRUE);
222225
$this->_slave = $slave;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ You may achieve high availability and load balancing using [Redis Sentinel](http
8282
specified should be a comma-separated list of Sentinel servers and the `sentinel_master` option should be specified
8383
to indicate the name of the sentinel master set (e.g. 'mymaster'). If using `sentinel_master` you may also specify
8484
`load_from_slaves` in which case a random slave will be chosen for performing reads in order to load balance across multiple Redis instances.
85+
Using the value '1' indicates to only load from slaves and '2' to include the master in the random read slave selection.
8586

8687
Example configuration:
8788

0 commit comments

Comments
 (0)