Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are ConnectRetry and KeepAlive not available in RedisConfiguration #496

Open
EmmanuelPonnudurai opened this issue Aug 31, 2022 · 1 comment

Comments

@EmmanuelPonnudurai
Copy link

EmmanuelPonnudurai commented Aug 31, 2022

I noticed that the RedisConfiguration does not provide a way to specify the KeepAlive and ConnectRetry options, which are available in the ConfigurationOptions class of StackExchange.Redis.

Why is this the case and how do I specify this option?

Right now, I have an internal class which is bound with the JSON config. I then convert that into an instance of RedisConfiguration and do AddStackExchangeRedisExtensions. The reason for maintaining another class is that I don't want to have the shape of the JSON section depend on the shape of the extension class. I would rather have it separate so that I can control things better. In any case I eventually make a conversion to the required class.

I can't even set them during initialization and stuck with how to do this exactly.

A sample of what I do,

var configForExtension = new RedisConfiguration
                {
                    AllowAdmin = myConfig.AllowAdmin,
                    Ssl = myConfig.Ssl,
                    ConnectTimeout = myConfig.ConnectTimeout,
                    SyncTimeout = myConfig.SyncTimeout,
                    AbortOnConnectFail = myConfig.AbortOnConnectFail,
                };

var hosts = new List<RedisHost>();
foreach (var item in myConfig.Hosts)
                {
                    hosts. Add(new RedisHost { Host = item.Host, Port = item. Port });
                }

configForExtension.Hosts = hosts.ToArray();

// can't do this because it's a readonly field
// configForExtension.ConfigurationOptions = new ConfigurationOptions(); 

// can't do this because at run time, the ConfigurationOptions would be NULL and result in exception
// configForExtension.ConfigurationOptions.KeepAlive = 10;
// configForExtension.ConfigurationOptions.ConnectRetry = 2;

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(configForExtension);

Any pointers would be appreciated. Thanks in advance.

  • OS: Windows
  • Runtime version: >NET 5
  • Version: 7.0.0
@EmmanuelPonnudurai
Copy link
Author

I think the version I am using has some issue where Hosts is null on initialization, which in turn cases a problem when getting the ConfigurationOptions since we are iterating over private member hosts which could be null. In latest code I see its not the case so I'm suspecting this.

Because when I initialized Hosts to Array.Empty<RedisHost>() and tried configForExtension.ConfigurationOptions.KeepAlive. It worked.

But the original question still remains. Why KeepAlive and ConnectRetry are not present in the top level configuration class and not even populated when you create the StackExchange.Redis.ConfigurationOptions

I feel it might be good expose a way to set ConfigurationOptions. What is the significance of the other RedisConfiguration when finally, its the ConfigurationOptions which matters. Please let me know if i am missing something with the intended use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant