简体   繁体   中英

Password for Redis with StackExchange.Redis

How do you specify the password for the Redis server with StackExchange.Redis? I am guessing you add it to the configuration string which is passed to the Connect method. 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". Longer version is: use ConfigurationOptions and set .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):

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"; 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).

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM