6

I am trying to make a simple example of reading and writing from azure redis cache and I get this error

An exception of type 'StackExchange.Redis.RedisConnectionException' occurred in StackExchange.Redis.dll but was not handled in user code

Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING

The code I am using is this, I changed dns and password

// Get Connection instance
ConnectionMultiplexer connection = ConnectionMultiplexer
    .Connect("xx.redis.cache.windows.net,ssl=false,password=...");
// Get database
IDatabase databaseCache = connection.GetDatabase();
// Add items
databaseCache.StringSet("foo1", "1");
databaseCache.StringSet("foo2", "2");
// Add items with experation value
databaseCache.StringSet("foo3", "3", TimeSpan.FromMinutes(20));

Stopwatch sw = new Stopwatch();

sw.Start();

// Get item value
string foo1Value = databaseCache.StringGet("foo1");

sw.Stop();

Console.WriteLine("Elapsed={0}", sw.Elapsed);
return View();
gunr2171
  • 16,104
  • 25
  • 61
  • 88
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
  • Also, try to check for solution here : http://stackoverflow.com/questions/30906891/cant-reconnect-to-azure-redis-via-stackexchange-redis/32852922#32852922 – Nigrimmist Sep 29 '15 at 20:13

2 Answers2

7

Azure Redis Cache only enables the SSL endpoint by default. The most secure approach is to set "ssl=true" when calling ConnectionMultiplexer.Connect().

Alternatively, you can use the Azure Portal to enable the non-SSL endpoint on your Azure Redis Cache, but then your password and all data will be sent in clear text.

Mike Harder
  • 1,765
  • 16
  • 12
  • This may be duplicate of http://stackoverflow.com/questions/28725437/azure-redis-unable-to-connect-to-redis-servers/29837033#29837033 – yantaq Apr 24 '15 at 19:50
6

I had exact same exception and it turned out to be corporate firewall, which is blocking port 6379, 6380.

I copied my test console app in an environment outside company network and connection was successful. So if Redis server is running on the internet and your network is behind a firewall make sure the ports are open.

yantaq
  • 3,968
  • 2
  • 33
  • 34