Skip to content

Commit 7f6eb59

Browse files
committed
[redis] fix tests.
1 parent e44da9d commit 7f6eb59

8 files changed

+225
-165
lines changed

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- AMQP_DSN=amqp://guest:guest@rabbitmq:5672/mqdev
2222
- AMQPS_DSN=amqps://guest:guest@rabbitmqssl:5671
2323
- DOCTRINE_DSN=mysql://root:rootpass@mysql/mqdev
24+
- PREDIS_DSN=redis+predis://redis
25+
- PHPREDIS_DSN=redis+phpredis://redis
2426
- RABBITMQ_HOST=rabbitmq
2527
- RABBITMQ_USER=guest
2628
- RABBITMQ_PASSWORD=guest

pkg/redis/PhpRedis.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ public function connect(): void
7474

7575
$this->redis = new \Redis();
7676

77-
$connectionMethod = $this->config['persisted'] ? 'pconnect' : 'connect';
77+
$connectionMethod = $this->config['persistent'] ? 'pconnect' : 'connect';
7878

7979
$result = call_user_func(
8080
[$this->redis, $connectionMethod],
8181
'unix' === $this->config['scheme'] ? $this->config['path'] : $this->config['host'],
8282
$this->config['port'],
8383
$this->config['timeout'],
84-
$this->config['persisted'] ? ($this->config['phpredis_persistent_id'] ?? null) : null,
84+
$this->config['persistent'] ? ($this->config['phpredis_persistent_id'] ?? null) : null,
8585
$this->config['phpredis_retry_interval'] ?? null,
8686
$this->config['read_write_timeout']
8787
);

pkg/redis/RedisConnectionFactory.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RedisConnectionFactory implements PsrConnectionFactory
3333
* 'password' => Accepts a value used to authenticate with a Redis server protected by password with the AUTH command.
3434
* 'async' => Specifies if connections to the server is estabilished in a non-blocking way (that is, the client is not blocked while the underlying resource performs the actual connection).
3535
* 'persistent' => Specifies if the underlying connection resource should be left open when a script ends its lifecycle.
36+
* 'lazy' => The connection will be performed as later as possible, if the option set to true
3637
* 'timeout' => Timeout (expressed in seconds) used to connect to a Redis server after which an exception is thrown.
3738
* 'read_write_timeout' => Timeout (expressed in seconds) used when performing read or write operations on the underlying network resource after which an exception is thrown.
3839
* 'predis_options' => An array of predis specific options.
@@ -65,7 +66,7 @@ public function __construct($config = 'redis:')
6566
$config = $this->parseDsn($config);
6667
} elseif (is_array($config)) {
6768
if (array_key_exists('dsn', $config)) {
68-
$config = array_replace($config, $this->parseDsn($config['dsn']));
69+
$config = array_replace_recursive($config, $this->parseDsn($config['dsn']));
6970

7071
unset($config['dsn']);
7172
}
@@ -120,9 +121,11 @@ private function parseDsn(string $dsn): array
120121
));
121122
}
122123

123-
$database = null;
124-
if ('unix' !== $dsn->getSchemeProtocol() && $dsn->getPath()) {
125-
$database = ltrim($dsn->getPath());
124+
$database = $dsn->getInt('database');
125+
126+
// try use path as database name if not set.
127+
if (null === $database && 'unix' !== $dsn->getSchemeProtocol() && null !== $dsn->getPath()) {
128+
$database = (int) ltrim($dsn->getPath(), '/');
126129
}
127130

128131
return array_filter(array_replace($dsn->getQuery(), [
@@ -152,9 +155,11 @@ private function defaultConfig(): array
152155
'password' => null,
153156
'async' => false,
154157
'persistent' => false,
158+
'lazy' => true,
155159
'timeout' => 5.0,
156160
'read_write_timeout' => null,
157161
'predis_options' => null,
162+
'ssl' => null,
158163
];
159164
}
160165
}

pkg/redis/Symfony/RedisTransportFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function addConfiguration(ArrayNodeDefinition $builder)
5757
->cannotBeEmpty()
5858
->info('A custom redis service id, used with vendor true only')
5959
->end()
60-
->booleanNode('persisted')
60+
->booleanNode('persistent')
6161
->defaultFalse()
62-
->info('bool, Whether it use single persisted connection or open a new one for every context')
62+
->info('bool, Whether it use single persistent connection or open a new one for every context')
6363
->end()
6464
->booleanNode('lazy')
6565
->defaultTrue()

0 commit comments

Comments
 (0)