Skip to content

Why are ConnectRetry and KeepAlive not available in RedisConfiguration #496

@EmmanuelPonnudurai

Description

@EmmanuelPonnudurai

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions