[英]Password for Redis with StackExchange.Redis
How do you specify the password for the Redis server with StackExchange.Redis?如何使用 StackExchange.Redis 为 Redis 服务器指定密码? I am guessing you add it to the configuration string which is passed to the Connect method.我猜你将它添加到传递给 Connect 方法的配置字符串中。 I can't seem to find the format in which it needs to be specified.我似乎找不到需要指定的格式。
I will add a full list of the key/value pairs to the configuration docs tomorrow.明天我将在配置文档中添加完整的键/值对列表。 Short version is: probably "foo,password=value".简短版本是:可能是“foo,password=value”。 Longer version is: use ConfigurationOptions
and set .Password
.更长的版本是:使用ConfigurationOptions
并设置.Password
。 The document shows you how to switch between the two layouts.该文档向您展示了如何在两种布局之间切换。
This is the way I got it working (note that simply adding the password like "localhost:6379,password=value"
didn't work for me - it needs to be set in the options):这就是我让它工作的方式(请注意,简单地添加像"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();
Assuming that you're running it via:假设您通过以下方式运行它:
docker run -d -p 6379:6379 --name yourRedisInstance redis --requirepass yourPassword
If the docker image wasn't run with a password, simply remove the line options.Password = "yourPassword";
如果 docker 映像没有使用密码运行,只需删除行options.Password = "yourPassword";
In that case, everyone can access the Redis service without a password (which you should not do if you have data in the cache that needs to be protected).在这种情况下,每个人都可以在没有密码的情况下访问 Redis 服务(如果缓存中有需要保护的数据,则不应这样做)。
I use this Connection string and it work fine for me:我使用这个连接字符串,它对我来说很好用:
127.0.0.1:6379,password=**********,ssl=False,abortConnect=False
if you are using a local, you can use like this如果你使用的是本地的,你可以像这样使用
"localhost, port:6379, password="YOUR_PASSWORD""
in server在服务器中
"http://server, port:6379, password="YOUR_PASSWORD"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.