Reputation: 559
I'm trying to use Azure Redis cache in my MVC 4.6 app but getting connection errors. This is the error:
No connection is available to service this operation: GET c7fc43f3-47c4-43cb-94ff-50527b1cda0c_TokenCache; It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. ConnectTimeout; IOCP: (Busy=3,Free=997,Min=2,Max=1000), WORKER: (Busy=2,Free=4093,Min=2,Max=4095), Local-CPU: 100%
My web.config has:
<add key="ida:CacheConnection" value="myCache.redis.cache.windows.net:6380,password=bpPQX6jeocNjyX1FqrvVztGMQqjekXbUXFjGkiZOyCE=,ssl=True,abortConnect=False,connectTimeout=30,syncTimeout=3000,ConnectRetry=3" />
My packages.config has:
<package id="StackExchange.Redis" version="1.2.0" targetFramework="net45" />
I followed this MSDN article to configure Aazure Redis server and client.
I tried to use client side cmd line tool to verify the connection even that is not working. Not giving me any sign of success or failure. This is my command:
C:\Program Files\Redis>redis-cli -h "myCache.redis.cache.windows.net" -a bpPQX= -p 6379
I tried -p 6380 as well but nothing changed.
Upvotes: 3
Views: 5796
Reputation: 61
Update your connection string
Upgrade your StackExchange.Redis nuget package to latest if you can.
Set the config option for ReconnectRetryPolicy in your C# code to be ExponentialRetry https://stackexchange.github.io/StackExchange.Redis/Configuration.html#reconnectretrypolicy
private static readonly Lazy<ConfigurationOptions> configOptions = new Lazy<ConfigurationOptions>(() =>
{
var connections = ConfigurationManager.ConnectionStrings["redis-connection"].ConnectionString;
var configOptions = ConfigurationOptions.Parse(connections);
configOptions.ClientName = "MyApp-RedisCacheProvider";
//configOptions.SyncTimeout = 100000; // don`t do this in code, set it in your connection string
//configOptions.AbortOnConnectFail = false; // don`t do this in code, set it in your connection string
/*
* The default is LinearRetry which can cause congestion at virtually the same time on multiple parallel threads.
* Use ExponentialRetry so that a degree of randomness is used in the timing across multiple threads.
*/
configOptions.ReconnectRetryPolicy = new ExponentialRetry(5000, 10000);
return configOptions;
});
private static readonly Lazy<ConnectionMultiplexer> connection = new Lazy<ConnectionMultiplexer>(
() => ConnectionMultiplexer.Connect(configOptions.Value));
Implement IDisposable to dispose the object after its use
public void Dispose()
{
try {
if (connection.IsValueCreated)
{
connection.Value.Dispose();
}
} catch { }
}
Upvotes: 0
Reputation: 11913
I had this same problem but in my case it was because a private endpoint had been setup on the Redis instance and this blocks all non-local connections. Check if you have a private endpoint setup.
Upvotes: 0
Reputation: 6245
You should go to your Redis Cache resource blade's Advanced Settings
in the Azure portal, set Allow access only via SSL
to No
and Save the setting.
You should be able to connect to your Redis cache via Redis CLI:
redis-cli -h "myCache.redis.cache.windows.net" -a bpPQX=
-p 6379
can be optional because the default Non-SSL port for Azure Redis Cache is 6379.
Reference: StackExchange.Redis Configuration Doc
Upvotes: 0
Reputation: 704
Set in Azure Portal: Non-SSL port (6379) enabled
.
Try to connect to port 6379
, using CLI
.
I don't think that Redis-CLI can connect to SSL port (6380)
Upvotes: 1