Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 781
Abhishek Nanda Avatar asked May 28 '14 23:05

Abhishek Nanda


2 Answers

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.

like image 103
Marc Gravell Avatar answered Dec 31 '22 20:12

Marc Gravell


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

like image 30
Matt Avatar answered Dec 31 '22 19:12

Matt