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

Sentinel support? #253

Closed
weare8 opened this issue Apr 27, 2020 · 11 comments
Closed

Sentinel support? #253

weare8 opened this issue Apr 27, 2020 · 11 comments

Comments

@weare8
Copy link

weare8 commented Apr 27, 2020

Having built a 3 node Redis cluster with Sentinel in front and using StackExchange.Redis.Extensions with the below configuration.

The problem is I need to pass the Sentinel cluster nodes and not the Redis nodes, the below result to blocking the application from starting since it can't create the connections correctly, any Sentinel support or plans to support in the future?

"Redis": {
    "Password": "super_secret_password",
    "AllowAdmin": true,
    "Ssl": false,
    "ConnectTimeout": 3000,
    "ConnectRetry": 2,
    "Database": 0,
    "Hosts": [
      {
        "Host": "sentinel-1.domain.com",
        "Port": 26379
      },
      {
        "Host": "sentinel-2.domain.com",
        "Port": 26379
      },
      {
        "Host": "sentinel-3.domain.com",
        "Port": 26379
      }
    ]
  }

Configuring the DI container.

var redisConfiguration = configuration.GetSection(redisSettingsJsonSection).Get<RedisConfiguration>();
services.AddSingleton(redisConfiguration);
services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();
services.AddSingleton(_ => new Utf8JsonSerializer());
services.AddSingleton(provider =>
                provider.GetService<IRedisCacheClient>().GetDbFromConfiguration());

// Setting up RedLock for distributed locking support, not sure if the below is correct

services.AddSingleton<IDistributedLockFactory>(provider =>
                RedLockFactory.Create(new List<RedLockMultiplexer>()
                {
                    new RedLockMultiplexer(
                        (ConnectionMultiplexer) provider.GetRequiredService<IRedisCacheConnectionPoolManager>()
                            .GetConnection())
                })
            );

When I start the ASP.NET Core API 3.1 I get the below messages and it just hangs, sometimes might pass to the next call stack method but takes forever, you might even have to restart the IDE to unblock it.

dbug: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
Checking if there are any invalid connections...
dbug: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
The pool size is 5 and it requires new 5 connections.
dbug: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
Creating new Redis connection.

@imperugo
Copy link
Owner

Hi @weare8
thanks for the feedback.

About Sentinel, we didn't implement it yet. We are thinking to do a refactoring on connection part (#182) for the version v7 and we could add we could add this feature.

If you need it soon, please open a PR and I'll be happy to merge it into our code.

About AspNet Core, I suggest you to use the specific package. Take a look to the documentation here https://imperugo.gitbook.io/stackexchange-redis-extensions/asp.net-core

About the logging you are getting, that's correct. Out of the box the library uses the same logger you are using and all the messages are on Debug level.
If you don't want them into you output you can set a specific filter for the namespace StackExchange.Redis.Extensions.*

let me know if you need more info.

@imperugo imperugo added this to the Version 7.0 milestone Apr 27, 2020
@imperugo
Copy link
Owner

imperugo commented May 9, 2020

Hi @weare8
I'm looking here in order to add Sentinel support, but I don't understand what is missing with this library.

CommandMap is already available into the configuration. Maybe ServiceName is needed?

Let me know

@rabberbock
Copy link

@imperugo
Copy link
Owner

@rabberbock please try the 7.2.0 that support both connection string and ServiceName in redisConfiguration

@imperugo imperugo added the done label Jun 11, 2020
@weare8
Copy link
Author

weare8 commented Jun 11, 2020

The latest code I almost made it work is the below, I derived from RedisConfiguration and added ServiceName along with couple of more properties but still couldn't make it work.

var redisConfiguration = configuration.GetSection(redisSettingsJsonSection).Get<EightRedisConfiguration>();

    var configOptions = new ConfigurationOptions
            {
                ServiceName = redisConfiguration.ServiceName,
                TieBreaker = string.Empty,
                DefaultVersion = new Version(
                    redisConfiguration.DefaultVersionMajor,
                    redisConfiguration.DefaultVersionMinor,
                    redisConfiguration.DefaultVersionBuild),
                Password = redisConfiguration.Password,
                AbortOnConnectFail = redisConfiguration.AbortOnConnectFail,
                Ssl = redisConfiguration.Ssl,
                AllowAdmin = redisConfiguration.AllowAdmin,
                ConnectTimeout = redisConfiguration.ConnectTimeout,
                DefaultDatabase = redisConfiguration.Database
            };

            foreach (var redisHost in redisConfiguration.Hosts)
            {
                configOptions.EndPoints.Add(redisHost.Host, redisHost.Port);
            }

configOptions.CommandMap = redisConfiguration.IsSentinelCluster ? CommandMap.Sentinel : CommandMap.Default;

            services.AddSingleton(_ =>
                    ConnectionMultiplexer
                        .Connect(configOptions, logTextWriter)
                        .GetSentinelMasterConnection(configOptions));

JSON section:

"DefaultVersionMajor": 4,
    "DefaultVersionMinor": 0,
    "DefaultVersionBuild": 11,
    "ServiceName": "eight-sentinel",
    "IsSentinelCluster": true,
    "Password": "AWESOME_PASSWORD",
    "AllowAdmin": true,
    "Ssl": false,
    "ConnectTimeout": 3000,
    "ConnectRetry": 2,
    "Database": 0,
    "Hosts": [
      {
        "Host": "redis-1.weare8.com",
        "Port": 26379
      },
      {
        "Host": "redis-2.com",
        "Port": 26379
      },
      {
        "Host": "redis-3.com",
        "Port": 26379
      }
    ]

Check this SO question for a reference regarding my latest error, not related to the extensions since I stopped using it really: https://stackoverflow.com/questions/62288797/this-operation-has-been-disabled-in-the-command-map-and-cannot-be-used-auth-re

@imperugo
Copy link
Owner

@weare8 the 7.2 that is on nuget, has the Sentinel support, please try it

@weare8
Copy link
Author

weare8 commented Jun 11, 2020

OK great! Let me try it out thanks :) any special documentation on Sentinel setup?

@imperugo
Copy link
Owner

Need to write it, but basically just set the service name into the RedisConfiguration class.

See here

https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/core/StackExchange.Redis.Extensions.Core/Configuration/RedisConfiguration.cs#L42

@weare8
Copy link
Author

weare8 commented Jun 11, 2020

Maybe out of topic, I can add any service name for Sentinel to work, it's pretty much an identifier only correct?
Also, how do you know to grab the Sentinel CommandMap and Connection instead of the Redis one?

@imperugo
Copy link
Owner

Hi @weare8
you are right. Just pushed 6.2.1 that has this

14ecf3c

@imperugo
Copy link
Owner

Going to close this.

Please feel free to reopen in case you still have the issue.

Thanks

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

No branches or pull requests

3 participants