我在azure的vm中运行了一个.net核心应用程序,在那里我使用redis作为distributedcache的实现。通过这种方式,我们将用户会话存储在redis中,并可以在web场中共享。我们只使用redis来存储会话。我们正在用一个普通的示例为redis使用azure缓存。vm和redis都在同一个区域中。
加载项启动:
services.AddStackExchangeRedisCache(options => {
options.Configuration = configuration["RedisCache:ConnectionString"];
});
在web应用程序中,redis关闭连接时会出现间歇性问题。所有对redis的调用都是通过调用会话异步方法来管理的,如下所示。
public static async Task<T> Get<T>(this ISession session, string key) {
if (!session.IsAvailable)
await session.LoadAsync();
var value = session.GetString(key);
return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);
}
我们看到的错误是:
StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: EVAL; An existing connection was forcibly closed by the remote host.; IOCP: (Busy=0,Free=1000,Min=2,Max=1000), WORKER: (Busy=3,Free=32764,Min=512,Max=32767), Local-CPU: n/a
---> StackExchange.Redis.RedisConnectionException: SocketFailure on myredis.redis.cache.windows.net:6380/Interactive, Idle/Faulted, last: EVAL, origin: ReadFromPipe, outstanding: 1, last-read: 34s ago, last-write: 0s ago, keep-alive: 60s, state: ConnectedEstablished, mgr: 9 of 10 available, in: 0, last-heartbeat: 0s ago, last-mbeat: 0s ago, global: 0s ago, v: 2.0.593.37019
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
和
StackExchange.Redis.RedisConnectionException: SocketFailure on myredis.redis.cache.windows.net:6380/Interactive, Idle/Faulted, last: EXPIRE, origin: ReadFromPipe, outstanding: 1, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: ConnectedEstablished, mgr: 9 of 10 available, in: 0, last-heartbeat: 0s ago, last-mbeat: 0s ago, global: 0s ago, v: 2.0.593.37019
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
我们在超时期间没有遇到流量高峰,redis示例也没有承受任何重载。
我不知道如何进一步排除故障。你知道吗?
1条答案
按热度按时间ldioqlga1#
由于空闲时间过长,redis服务器可能会关闭连接。在azure缓存控件中,可以找到redis服务器的配置,看看是否可以找到超时设置。如果可以通过命令行发出命令,也可以发出此命令
如果为零,则表示没有超时。
那么问题是你的redis客户端。我对.net不太熟悉,不管你用什么客户端连接到redis服务器,检查超时选项或google搜索(客户端名称)+超时,看看你能不能找到有用的信息。