Connecting to Azure Redis Cache

Craig picture Craig · May 21, 2014 · Viewed 10.7k times · Source

I am trying to connect to the Preview Azure Redis Cache with the following code.

var options = new ConfigurationOptions();
options.EndPoints.Add("myname.redis.cache.windows.net", 6379);
options.Ssl = true;
options.Password = "VeryLongKeyCopiedFromPortal";
var connection = ConnectionMultiplexer.Connect(options);

When I do this I get the exception

"It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail"

What can be causing this?

Answer

Mike Harder picture Mike Harder · May 21, 2014

The port for SSL is 6380. Port 6379 is used for non-SSL. StackExchange.Redis defaults to these ports if not set, so you should be able to just remove the port from your code, like so:

var options = new ConfigurationOptions();
options.EndPoints.Add("myname.redis.cache.windows.net");
options.Ssl = true;
options.Password = "VeryLongKeyCopiedFromPortal";
var connection = ConnectionMultiplexer.Connect(options);

Alternatively, you can use a connection string instead of the ConfigurationOptions object:

var connection = ConnectionMultiplexer.Connect(
    "myname.redis.cache.windows.net,ssl=true,password=VeryLongKeyCopiedFromPortal");