Skip to content

Commit 7bb5068

Browse files
Added phpredis sentinel auth
1 parent 01b68b2 commit 7bb5068

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ snc_redis:
121121
parameters:
122122
database: 1
123123
password: pass
124+
sentinel_auth: pass1
125+
disable_sentinel_auth: false # default to false
126+
124127
```
125128

126129
The `service` is the name of the set of Redis instances.
@@ -131,6 +134,7 @@ If you use a password, it must be in the password parameter and must
131134
be omitted from the DSNs. Also make sure to use the sentinel port number
132135
(26379 by default) in the DSNs, and not the default Redis port.
133136
You can find more information about this on [Configuring Sentinel](https://redis.io/topics/sentinel#configuring-sentinel).
137+
`sentinel_auth` is used to set a specific password for Sentinel authentication. If you do not provide a `sentinel_auth` password, the default `password` will be used for Sentinel authentication. you can disable sentinel auth `disable_sentinel_auth` if you don't require
134138

135139
A setup using `RedisCluster` from `phpredis` could look like this:
136140

src/DependencyInjection/Configuration/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ private function addClientsSection(ArrayNodeDefinition $rootNode): void
155155
->scalarNode('database')->defaultNull()->end()
156156
->scalarNode('username')->defaultNull()->end()
157157
->scalarNode('password')->defaultNull()->end()
158+
->scalarNode('sentinel_auth')->defaultNull()->end()
159+
->booleanNode('disable_sentinel_auth')->defaultValue(false)->end()
158160
->booleanNode('logging')->defaultValue($this->debug)->end()
159161
->variableNode('ssl_context')->defaultNull()->end()
160162
->end()

src/Factory/PhpredisClientFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private function createClientFromSentinel(string $class, array $dsns, string $al
134134
'persistent' => $connectionPersistent,
135135
'retryInterval' => 5,
136136
'readTimeout' => $readTimeout,
137+
'auth' => $options['parameters']['disable_sentinel_auth'] ? null : ($options['parameters']['sentinel_auth'] ?? $dsn->getPassword() ?? null)
137138
];
138139
try {
139140
if ($isRelay || version_compare(phpversion('redis'), '6.0', '<')) {

0 commit comments

Comments
 (0)