Reputation: 8626
I have the below code to setup the Sentinel Redis connection.
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));
I receive the following exception.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
This operation has been disabled in the command-map and cannot be used: AUTH: RedisCommandException
at StackExchange.Redis.CommandMap.AssertAvailable(RedisCommand command) in /_/src/StackExchange.Redis/CommandMap.cs:line 169
at StackExchange.Redis.ConnectionMultiplexer..ctor(ConfigurationOptions configuration) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1141
at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration, LogProxy log, EventHandler`1& connectHandler) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 958
at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Object configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1014
at StackExchange.Redis.ConnectionMultiplexer.Connect(ConfigurationOptions configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1002
The configuration is the below.
"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.com",
"Port": 26379
},
{
"Host": "redis-2.com",
"Port": 26379
},
{
"Host": "redis-3.com",
"Port": 26379
}
]
I'm a bit lost with the issue and not sure the message behind it, I can connect using Redis Desktop Manager client to the sentinel cluster with just adding the first instance.
Upvotes: 1
Views: 1455
Reputation: 1438
I also had a similar issue and after some research, I realized they have some issues in the library, seems like there is an issue with using ConfigurationOptions
.
As it suggested here , it works if you create a connection via connection string instead
using(var connection=new ConnectionMultiplexer.Connect("10.1.3.11:26379,10.1.3.12:26379,10.1.3.13:26379,serviceName=redis-primary,AllowAdmin=true"))
{
// do stuff
}
you have to specify ServiceName
in the connection string in order to connect to Sentinel.
They introduced a new method SentinelConnect
which doesn't work with the same connection string!
if you are using StackExchange.Redis.Extensions.Core
library which doesn't have a constructor with connection string you should create an empty instance of RedisConfiguration and in ConnectionPoolManager implementation connect via ConnectionString.
Upvotes: 1