Skip to content

Commit e5f5a90

Browse files
committed
Add tests and support for sentinel user+pw combo
1 parent f576535 commit e5f5a90

File tree

11 files changed

+52
-33
lines changed

11 files changed

+52
-33
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
include:
1919
- dependency-versions: "lowest"
2020
php-version: "7.4"
21-
php-extensions: "redis-5.3.0"
21+
php-extensions: "redis-5.3.2"
2222
- symfony-require: "5.4.*"
2323
php-version: "8.2"
2424
php-extensions: "redis"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
sentinel monitor mymaster 127.0.0.1 6379 2
2+
user default on +@all ~* >sentinelauthdefaultpw
3+
user sentinelauth on +@all ~* >sentinelauthpw
24
appendonly no

Procfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
redis: redis-server .github/workflows/redis-configs/redis.conf --port 6379
2-
redis-acl: redis-server .github/workflows/redis-configs/redis-acl.conf --port 7099
3-
redis-sentinel: redis-server .github/workflows/redis-configs/redis-sentinel.conf --sentinel
4-
redis-node1: sh -c 'cd .github/workflows/redis-configs/redis-node1 && redis-server redis.conf --port 7079'
5-
redis-node2: sh -c 'cd .github/workflows/redis-configs/redis-node2 && redis-server redis.conf --port 7080'
6-
redis-node3: sh -c 'cd .github/workflows/redis-configs/redis-node3 && redis-server redis.conf --port 7081'
7-
redis-node4: sh -c 'cd .github/workflows/redis-configs/redis-node4 && redis-server redis.conf --port 7082'
8-
redis-node5: sh -c 'cd .github/workflows/redis-configs/redis-node5 && redis-server redis.conf --port 7083'
9-
redis-node6: sh -c 'cd .github/workflows/redis-configs/redis-node6 && redis-server redis.conf --port 7084'
1+
redis: sh -c 'cp .github/workflows/redis-configs/redis.conf /tmp/ && redis-server /tmp/redis.conf --port 6379'
2+
redis-acl: sh -c 'cp .github/workflows/redis-configs/redis-acl.conf /tmp/ && redis-server /tmp/redis-acl.conf --port 7099'
3+
redis-sentinel: sh -c 'cp .github/workflows/redis-configs/redis-sentinel.conf /tmp/ && redis-server /tmp/redis-sentinel.conf --sentinel'
4+
redis-node1: sh -c 'cp -R .github/workflows/redis-configs/redis-node1 /tmp/ && cd /tmp/redis-node1 && redis-server redis.conf --port 7079'
5+
redis-node2: sh -c 'cp -R .github/workflows/redis-configs/redis-node2 /tmp/ && cd /tmp/redis-node2 && redis-server redis.conf --port 7080'
6+
redis-node3: sh -c 'cp -R .github/workflows/redis-configs/redis-node3 /tmp/ && cd /tmp/redis-node3 && redis-server redis.conf --port 7081'
7+
redis-node4: sh -c 'cp -R .github/workflows/redis-configs/redis-node4 /tmp/ && cd /tmp/redis-node4 && redis-server redis.conf --port 7082'
8+
redis-node5: sh -c 'cp -R .github/workflows/redis-configs/redis-node5 /tmp/ && cd /tmp/redis-node5 && redis-server redis.conf --port 7083'
9+
redis-node6: sh -c 'cp -R .github/workflows/redis-configs/redis-node6 /tmp/ && cd /tmp/redis-node6 && redis-server redis.conf --port 7084'

docs/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ A setup using `predis`, `phpredis` or `relay` sentinel replication could look li
110110
snc_redis:
111111
clients:
112112
default:
113-
type: "predis" # or "phpredis", or "relay"
113+
type: "phpredis" # or "predis", or "relay"
114114
alias: default
115115
dsn:
116116
- redis://localhost:26379
@@ -121,8 +121,8 @@ snc_redis:
121121
parameters:
122122
database: 1
123123
password: pass
124-
sentinel_auth: pass1 # default to null
125-
124+
sentinel_username: myuser # default to null
125+
sentinel_password: mypass # default to null
126126
```
127127

128128
The `service` is the name of the set of Redis instances.
@@ -133,7 +133,6 @@ If you use a password, it must be in the password parameter and must
133133
be omitted from the DSNs. Also make sure to use the sentinel port number
134134
(26379 by default) in the DSNs, and not the default Redis port.
135135
You can find more information about this on [Configuring Sentinel](https://redis.io/topics/sentinel#configuring-sentinel).
136-
`sentinel_auth` is used to set a specific password for Sentinel authentication. default is null (No authentication)
137136
A setup using `RedisCluster` from `phpredis` could look like this:
138137

139138
``` yaml

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
config.allowUnfree = true;
1818
config.allowInsecurePredicate = pkg: pkgs.lib.getName pkg == "openssl";
1919
};
20-
php = pkgs.php82.buildEnv {
20+
php = pkgs.php83.buildEnv {
2121
extensions = (
2222
{
2323
all,

src/DependencyInjection/Configuration/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +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()
158+
->scalarNode('sentinel_username')->defaultNull()->end()
159+
->scalarNode('sentinel_password')->defaultNull()->end()
159160
->booleanNode('logging')->defaultValue($this->debug)->end()
160161
->variableNode('ssl_context')->defaultNull()->end()
161162
->end()

src/Factory/PhpredisClientFactory.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public function create(string $class, array $dsns, array $options, string $alias
111111
}
112112

113113
/**
114-
* @param class-string $class
115-
* @param list<RedisDsn> $dsns
116-
* @param array{service: ?string, connection_persistent: ?bool, connection_timeout: ?string, read_write_timeout: ?string} $options
114+
* @param class-string $class
115+
* @param list<RedisDsn> $dsns
116+
* @param array{service: ?string, connection_persistent: ?bool, connection_timeout: ?string, read_write_timeout: ?string, parameters: array{sentinel_username: string, sentinel_password: string}} $options
117117
*
118118
* @return Redis|Relay
119119
*/
@@ -125,6 +125,7 @@ private function createClientFromSentinel(string $class, array $dsns, string $al
125125
$connectionTimeout = $options['connection_timeout'] ?? 0;
126126
$connectionPersistent = $options['connection_persistent'] ? $masterName : null;
127127
$readTimeout = $options['read_write_timeout'] ?? 0;
128+
$parameters = $options['parameters'];
128129

129130
foreach ($dsns as $dsn) {
130131
$args = [
@@ -134,7 +135,7 @@ private function createClientFromSentinel(string $class, array $dsns, string $al
134135
'persistent' => $connectionPersistent,
135136
'retryInterval' => 5,
136137
'readTimeout' => $readTimeout,
137-
'auth' => $options['parameters']['sentinel_auth'] ?? null,
138+
'auth' => [$parameters['sentinel_username'], $parameters['sentinel_password']],
138139
];
139140
try {
140141
if ($isRelay || version_compare(phpversion('redis'), '6.0', '<')) {

tests/DependencyInjection/SncRedisExtensionEnvTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function testPredisDefaultParameterConfig(): void
5353
'database' => null,
5454
'username' => null,
5555
'password' => null,
56-
'sentinel_auth' => null,
56+
'sentinel_username' => null,
57+
'sentinel_password' => null,
5758
'logging' => false,
5859
],
5960
'commands' => ['foo' => 'Foo\Bar\Baz'],
@@ -133,7 +134,8 @@ public function testPhpredisFullConfig(): void
133134
'database' => null,
134135
'username' => null,
135136
'password' => null,
136-
'sentinel_auth' => null,
137+
'sentinel_username' => null,
138+
'sentinel_password' => null,
137139
'logging' => false,
138140
],
139141
'connection_async' => false,
@@ -172,7 +174,8 @@ public function testPhpredisWithAclConfig(): void
172174
'database' => null,
173175
'logging' => false,
174176
'ssl_context' => null,
175-
'sentinel_auth' => null,
177+
'sentinel_username' => null,
178+
'sentinel_password' => null,
176179
],
177180
'prefix' => null,
178181
'read_write_timeout' => null,

tests/Factory/PhpredisClientFactoryTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,17 @@ public function testCreateMinimalClusterConfig(): void
107107

108108
/**
109109
* @requires extension relay
110-
* @testWith ["RedisSentinel", "Redis"]
111-
* ["Relay\\Sentinel", "Relay\\Relay"]
110+
* @testWith ["RedisSentinel", "Redis", null, "sentinelauthdefaultpw"]
111+
* ["RedisSentinel", "Redis", "sentinelauth", "sentinelauthpw"]
112+
* ["Relay\\Sentinel", "Relay\\Relay", null, "sentinelauthdefaultpw"]
113+
* ["Relay\\Sentinel", "Relay\\Relay", "sentinelauth", "sentinelauthpw"]
112114
*/
113-
public function testCreateSentinelConfig(string $sentinelClass, string $outputClass): void
114-
{
115+
public function testCreateSentinelConfig(
116+
string $sentinelClass,
117+
string $outputClass,
118+
?string $sentinelUser,
119+
?string $sentinelPassword
120+
): void {
115121
$this->logger->method('debug')->with(...$this->withConsecutive(
116122
[$this->stringContains('Executing command "CONNECT 127.0.0.1 6379 5 <null>')],
117123
['Executing command "AUTH sncredis"'],
@@ -130,6 +136,10 @@ public function testCreateSentinelConfig(string $sentinelClass, string $outputCl
130136
'connection_timeout' => 5,
131137
'connection_persistent' => false,
132138
'service' => 'mymaster',
139+
'parameters' => [
140+
'sentinel_username' => $sentinelUser,
141+
'sentinel_password' => $sentinelPassword,
142+
],
133143
],
134144
'phpredissentinel',
135145
true,

0 commit comments

Comments
 (0)