Skip to content

Commit 3d3e497

Browse files
Merge pull request #55 from abramchenkoaa/master
Support of the separate password for Redis Sentinel Auth
2 parents 3df52a7 + 101da10 commit 3d3e497

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/Cm/RedisSession/Handler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
*/
5252

5353
use Cm\RedisSession\Handler\ConfigInterface;
54+
use Cm\RedisSession\Handler\ConfigSentinelPasswordInterface;
5455
use Cm\RedisSession\Handler\LoggerInterface;
5556

5657
class Handler implements \SessionHandlerInterface
@@ -294,6 +295,9 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r
294295
$sentinelMaster = $this->config->getSentinelMaster();
295296
$sentinelVerifyMaster = $this->config->getSentinelVerifyMaster();
296297
$sentinelConnectRetries = $this->config->getSentinelConnectRetries();
298+
$sentinelPassword = $this->config instanceof ConfigSentinelPasswordInterface
299+
? $this->config->getSentinelPassword()
300+
: $pass;
297301

298302
// Connect and authenticate
299303
if ($sentinelServers && $sentinelMaster) {
@@ -306,9 +310,9 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r
306310
$sentinelClient = new \Credis_Client($server, NULL, $timeout, $persistent);
307311
$sentinelClient->forceStandalone();
308312
$sentinelClient->setMaxConnectRetries(0);
309-
if ($pass) {
313+
if ($sentinelPassword) {
310314
try {
311-
$sentinelClient->auth($pass);
315+
$sentinelClient->auth($sentinelPassword);
312316
} catch (\CredisException $e) {
313317
// Prevent throwing exception if Sentinel has no password set (error messages are different between redis 5 and redis 6)
314318
if ($e->getCode() !== 0 || (
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
==New BSD License==
4+
5+
Copyright (c) 2013, Colin Mollenhour
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
* The name of Colin Mollenhour may not be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
* Redistributions in any form must not change the Cm_RedisSession namespace.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
24+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
namespace Cm\RedisSession\Handler;
32+
33+
interface ConfigSentinelPasswordInterface
34+
{
35+
/**
36+
* Get Redis Sentinel password
37+
*
38+
* @return string|null
39+
*/
40+
public function getSentinelPassword();
41+
}

0 commit comments

Comments
 (0)