Redis Docker Container Error ArgumentException: No endpoints specified (Parameter 'configuration')


Question: How do you solve the error that comes when you are trying to cache an object to Redis and the error says "ArgumentException: No endpoints specified (Parameter 'configuration')".


Login to See the Rest of the Answer

Answer:
When working with Redis Docker Container in Asp.Net 5 Application, in order to connect to the external Redis Cache Server you will need to provide the Configuration Settings. The ConfigurationOptions requires the Endpoints to have two parameters, one is for the IP Address (Just IP Address, do not include HTTP or HTTPS) and the other one is for the port. Make sure you put all these settings in the appsettings.json and use the IConfiguration Interface to get the values from the file.

See the code below:

            services.AddDistributedMemoryCache();
            services.AddStackExchangeRedisCache(options =>
            {
            options.InstanceName = _configuration.GetValue<string>("NameOfInstanceHere");
            options.ConfigurationOptions = new ConfigurationOptions()
            {
                EndPoints = { { _configuration.GetValue<string>("SettingsBlock:ConnectionString"), PortNumberComesInHere } },
                ConnectRetry = 2,
                ReconnectRetryPolicy = new LinearRetry(10),
                //Ssl = true,
                //AbortOnConnectFail = false,
                ConnectTimeout = 5000,
                //SyncTimeout = 1000,
                DefaultDatabase = 0,
                 Password = _configuration.GetValue<string>("Password")
            };



        });

To solve the "ArgumentException: No endpoints specified" error when caching an object to Redis, you need to ensure that you provide the necessary configuration settings. Here are the steps:

  1. Open your appsettings.json file.
  2. Add the Redis cache configuration settings, including the IP address and port, under the "Redis" section. For example:
"Redis": {
  "ConnectionString": "localhost:6379"
}
  1. In your code, make sure you have a reference to the IConfiguration interface to retrieve the values from the configuration file.
  2. Configure the Redis cache in your Startup.cs file using the obtained configuration values. For example:

    using StackExchange.Redis;
    public void ConfigureServices(IServiceCollection services)
    {
    
        IConfigurationSection redisConfig = Configuration.GetSection("Redis");
        services.AddSingleton<IConnectionMultiplexer>(sp =>
        {
            string connectionString = redisConfig.GetValue<string>("ConnectionString");
            return ConnectionMultiplexer.Connect(connectionString);
        });
    }
    ?

     

    1. Finally, you can use the Redis cache in your code by injecting the IConnectionMultiplexer instance and accessing the cache through it.

    By following these steps, you should be able to resolve the "ArgumentException: No endpoints specified" error and successfully cache objects to Redis.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]