![](/img/trans.png)
[英]No connection is available to service this operation: when using Azure Redis Cache
[英]Azure Redis Cache error No connection is available to service this operation:
我正在尝试在我的 MVC 4.6 应用程序中使用 Azure Redis 缓存,但出现连接错误。 这是错误:
没有连接可用于服务此操作:GET c7fc43f3-47c4-43cb-94ff-50527b1cda0c_TokenCache; 无法连接到 redis 服务器; 要创建断开连接的多路复用器,请禁用 AbortOnConnectFail。 连接超时; IOCP: (Busy=3,Free=997,Min=2,Max=1000), WORKER: (Busy=2,Free=4093,Min=2,Max=4095), Local-CPU: 100%
我的 web.config 有:
<add key="ida:CacheConnection" value="myCache.redis.cache.windows.net:6380,password=bpPQX6jeocNjyX1FqrvVztGMQqjekXbUXFjGkiZOyCE=,ssl=True,abortConnect=False,connectTimeout=30,syncTimeout=3000,ConnectRetry=3" />
我的 packages.config 有:
<package id="StackExchange.Redis" version="1.2.0" targetFramework="net45" />
我按照这篇MSDN文章配置了 Aazure Redis 服务器和客户端。
我尝试使用客户端 cmd 线路工具来验证连接,即使它不起作用。 没有给我任何成功或失败的迹象。 这是我的命令:
C:\Program Files\Redis>redis-cli -h "myCache.redis.cache.windows.net" -a bpPQX= -p 6379
我也尝试了 -p 6380 但没有任何改变。
在Azure门户中设置: Non-SSL port (6379) enabled
。
尝试使用CLI
连接到端口6379
。 我不认为Redis-CLI可以连接到SSL端口(6380)
您应该转到Azure门户中的Redis缓存资源刀片的Advanced Settings
,将“ Allow access only via SSL
”设置为“ No
并保存设置。
您应该能够通过Redis CLI连接到Redis缓存:
redis-cli -h "myCache.redis.cache.windows.net" -a bpPQX=
-p 6379
可以是可选的,因为Azure Redis Cache的默认非SSL端口是6379。
我遇到了同样的问题,但就我而言,这是因为在 Redis 实例上设置了一个私有端点,这会阻止所有非本地连接。 检查您是否有专用端点设置。
更新您的连接字符串
如果可以,请将您的 StackExchange.Redis nuget package 升级到最新版本。
在 C# 代码中将 ReconnectRetryPolicy 的配置选项设置为 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));
实施 IDisposable 以在使用后处理 object
public void Dispose() { try { if (connection.IsValueCreated) { connection.Value.Dispose(); } } catch { } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.