Default database 0 overrides StackExchange.Redis defaultDatabase in configuration string
shaneqld opened this issue · comments
Version Information
Version of Akka.NET? 1.4.31
Which Akka.NET Modules? Akka.Persistence.Redis
Describe the bug
Akka.Persistence.Redis describes using the configuration-string
using the StackExchange.Redis configuration string format. One option of the configuration of StackExchange.Redis is defaultDatabase
, which selects the database the library should use by default.
This configuration setting is overridden by the Akka.Persistence.Redis setting database
, which is undocumented (at least in the README) and defaults to 0.
As such, attempting to set the database using the configuration string does not work, always results in using database 0 and is not immediately clear why.
I suggest that this setting database
be documented. Additionally, if database
is unspecified, I think it shouldn't override the configuration string-specified defaultDatabase
(however I can see this might inadvertently break existing deployments if they have used a non-zero defaultDatabase
but are, in fact, using database 0).
Yep, we absolutely need to fix this.
_database = new Lazy<IDatabase>(() =>
{
var redisConnection = ConnectionMultiplexer.Connect(_settings.ConfigurationString);
IsClustered = redisConnection.IsClustered();
return redisConnection.GetDatabase(_settings.Database);
});
Above is the code that handles redis
connection:
- When you set the
defaultDatabase
in theconnection-strings
, you have to also updatedatabase
setting if thedefaultDatabase
is not0
. The reason for this is because theconnection-strings
is not being parsed and the only way, currently, to determine the database to use is from thedatabase
setting! We need to improve the documentation, if this is not already spelt out. #195 - We can also parse the
connection-strings
and if we finddefaultDabase
, then we can use the value from it instead and skip/set thedatabase
value! #194