【发布时间】:2020-10-15 01:10:02
【问题描述】:
好吧,我正在使用 Net Core 2.1 和 lib Microsoft.Extensions.Caching.Redis ver 2.1.2,当我只使用一个 Redis 节点时,一切正常。
使用单个节点:
services.AddDistributedRedisCache(ops =>
{
ops.Configuration = "localhost:6379";
ops.InstanceName = "master";
});
但现在,我正在尝试将 Redis 与 Sentinel 一起使用,因此我将配置更改为(遵循本指南 https://stackexchange.github.io/StackExchange.Redis/Configuration.html):
services.AddDistributedRedisCache(ops =>
{
ops.Configuration = "localhost,serviceName:mymaster";
ops.InstanceName = "master";
});
所以,我有一个 docker-compose.yml 来使用 sentinel 启动 redis 节点:
version: '2'
services:
redis-master:
image: bitnami/redis:5.0
environment:
ALLOW_EMPTY_PASSWORD: 'yes'
REDIS_REPLICATION_MODE: 'master'
ports:
- '6379:6379'
redis-slave1:
image: bitnami/redis:5.0
environment:
ALLOW_EMPTY_PASSWORD: 'yes'
REDIS_REPLICATION_MODE: 'slave'
REDIS_MASTER_HOST: redis-master
depends_on:
- redis-master
ports:
- '6380:6380'
redis-slave2:
image: bitnami/redis:5.0
environment:
ALLOW_EMPTY_PASSWORD: 'yes'
REDIS_REPLICATION_MODE: 'slave'
REDIS_MASTER_HOST: redis-master
depends_on:
- redis-master
ports:
- '6381:6381'
redis-sentinel:
image: bitnami/redis-sentinel:5.0
environment:
REDIS_MASTER_HOST: redis-master
REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS: 10000
ports:
- '26379:26379'
当我启动我的应用程序时一切正常,所以我关闭了主节点以测试哨兵并在 Asp Net Core 中得到以下错误:
RedisConnectionException: SocketClosed on localhost:6379/Subscription, origin: ProcessReadBytes, input-buffer: 0, outstanding: 0, last-read: 14s ago, last-write: 14s ago, unanswered-write: 1998113s ago, keep-alive: 60s, pending: 0, state: ConnectedEstablished, in: 0, ar: 0, last-heartbeat: 0s ago, last-mbeat: 0s ago, global: 0s ago
Unknown location
RedisConnectionException: No connection is available to service this operation: EVAL; SocketClosed on localhost:6379/Subscription, origin: ProcessReadBytes, input-buffer: 0, outstanding: 0, last-read: 14s ago, last-write: 14s ago, unanswered-write: 1998113s ago, keep-alive: 60s, pending: 0, state: ConnectedEstablished, in: 0, ar: 0, last-heartbeat: 0s ago, last-mbeat: 0s ago, global: 0s ago
StackExchange.Redis.ConnectionMultiplexer.ThrowFailed<T>(TaskCompletionSource<T> source, Exception unthrownException) in ConnectionMultiplexer.cs, line 2000
好吧,如果我再次启动主节点,一切正常,但这不是预期的行为。我希望在关闭主节点后,哨兵将一个从属提升为主,我可以继续使用redis而不会出错。
我错过了什么吗?
【问题讨论】:
标签: asp.net-core .net-core redis stackexchange.redis