问题:
如何正确地使用以下方法进行身份验证并不明显:
当使用ServiceStack.Redis解决方案时。
根据医生的说法为redis/sentinel提供密码的一种适当方法是通过URL以下列方式设置密码:
var sentinel = new RedisSentinel(new[] {"password@localhost:26381"})这很好,但是如何为redis连接本身提供密码呢?我在URL中指定的密码不会复制到redis连接中。
我找到了一个解决办法,这似乎是可行的,但我不确定它是否真的涵盖了所有可能的情况:
//Get the original factory
var clientFactory = RedisConfig.ClientFactory;
//Decorate it with the logic that sets a password.
RedisConfig.ClientFactory = c =>
{
c.Password = "password";
return clientFactory.Invoke(c);
};
//Continue to initialize sentinels
var sentinel = new RedisSentinel(new[] {"password@localhost:26379"});这似乎实际上将解决问题,并将提供一个密码连接到redis实例(而不是哨兵)。
的问题是:这是推荐的方法吗?还是有更好的方法?
发布于 2021-04-20 15:12:24
您可以使用RedisSentinel HostFilter来自定义哨兵连接到的各个主机的连接字符串,例如:
sentinel.HostFilter = host => $"password@{host}";https://stackoverflow.com/questions/67181489
复制相似问题