使用 StackExchange.Redis 的 Redis 密码

Abh*_*nda 5 stackexchange.redis

如何使用 StackExchange.Redis 指定 Redis 服务器的密码?我猜你将它添加到传递给 Connect 方法的配置字符串中。我似乎无法找到需要指定的格式。

Mar*_*ell 10

明天我会将键/值对的完整列表添加到配置文档中。简短版本是:可能是“foo,password=value”。更长的版本是: useConfigurationOptions和 set .Password。该文档向您展示了如何在两种布局之间切换。

  • @balint 关闭;它实际上是:https://stackexchange.github.io/StackExchange.Redis/Configuration - 移动到 github 页面是破坏链接的原因 (2认同)

Mat*_*att 7

这就是我让它工作的方式(请注意,简单地添加密码"localhost:6379,password=value"对我来说不起作用 - 它需要在选项中设置):

var options = ConfigurationOptions.Parse("localhost:6379"); // host1:port1, host2:port2, ...
options.Password = "yourPassword";      
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(options);

IDatabase conn = redis.GetDatabase();
Run Code Online (Sandbox Code Playgroud)

假设您通过以下方式运行它:

docker run -d -p 6379:6379 --name yourRedisInstance redis --requirepass yourPassword
Run Code Online (Sandbox Code Playgroud)

如果 docker 映像未使用密码运行,只需删除该行options.Password = "yourPassword";In that case, every person can access the Redis service without a password(如果缓存中有需要保护的数据,则不应这样做)。