I use the following to connect to Redis without problems until today, now I have to explicitly specify the database parameter because of this:
ArgumentOutOfRangeException
Specified argument was out of the range of valid values. Parameter name: db at StackExchange.Redis.ConnectionMultiplexer.GetDatabase(Int32 db, Object asyncState) at MyServer.MyClass..cctor()
This is the configuration I used:
private static Lazy<ConnectionMultiplexer> MyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(MyRedisConnString);
});
public static ConnectionMultiplexer ConnGer
{
get
{
return MyConnection.Value;
}
}
and at class level:
private static readonly IDatabase RedisDb = RedisConfig.ConnGer.GetDatabase();
Providing the db parameter this way: RedisConfig.ConnGer.GetDatabase (0); bug fixed, of course; worry more about whether there have been any apparent violations lately because the class libraries are dotted with Redis!
UPDATE Thinking that I had solved the problem, for no apparent reason ConnectionMultiplexer started working with the specified configuration again. I tried defaultDatabase=0in a line and also tried as Configuration.Option and got this error:
Exception type: ArgumentException
Exception message: Keyword 'defaultDatabase' is not supported
at StackExchange.Redis.ConfigurationOptions.OptionKeys.Unknown(String key)
at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown)
at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration)
at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func 1 multiplexerFactory, TextWriter log)
at System.Lazy 1.CreateValue () `
and with ConfigOption mode:
Exception type: TypeInitializationException
Method not found: 'Void StackExchange.Redis.ConfigurationOptions.set_DefaultDatabase(System.Nullable 1<Int32>)'.
System.Lazy , .
0 GetDatabase() ; , .