Skip to content

Commit d8d70d0

Browse files
rvanlaakNyholm
authored andcommitted
Allow selecting Redis database via $config (#70)
1 parent 6b1b3aa commit d8d70d0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Factory/RedisFactory.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ public function getAdapter(array $config)
4848
throw new ConnectException('Could not connect authenticate connection to Redis database.');
4949
}
5050
}
51+
$config['database'] = $dsn->getDatabase();
52+
}
5153

52-
if ($dsn->getDatabase() !== null) {
53-
if (false === $client->select($dsn->getDatabase())) {
54-
throw new ConnectException(sprintf('Could not select Redis database with index "%s".', $dsn->getDatabase()));
55-
}
56-
}
54+
if (null !== $config['database'] && false === $client->select($config['database'])) {
55+
throw new ConnectException(sprintf('Could not select Redis database with index "%s".', $config['database']));
5756
}
5857

5958
$pool = new RedisCachePool($client);
@@ -77,11 +76,13 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
7776
'host' => '127.0.0.1',
7877
'port' => '6379',
7978
'pool_namespace' => null,
79+
'database' => null,
8080
]
8181
);
8282

8383
$resolver->setAllowedTypes('host', ['string']);
8484
$resolver->setAllowedTypes('port', ['string', 'int']);
8585
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
86+
$resolver->setAllowedTypes('database', ['int', 'null']);
8687
}
8788
}

0 commit comments

Comments
 (0)