akkadotnet / Akka.Persistence.Redis

Redis storage for Akka.NET Persistence

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 the connection-strings, you have to also update database setting if the defaultDatabase is not 0. The reason for this is because the connection-strings is not being parsed and the only way, currently, to determine the database to use is from the database 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 find defaultDabase, then we can use the value from it instead and skip/set the database value! #194