【发布时间】:2018-03-22 11:56:41
【问题描述】:
我正在使用 Redis 分布式缓存,故障转移模式与散列数据分布相结合。我的配置是:
Sentinel1 Sentinel4
Master1 Master2
Sentinel2 Sentinel5
Slave1 Slave2
Sentinel3 Sentinel6
在我的代码中,我需要使用哨兵访问主缓存。
我要指出哪一个?
我想我必须在 ConnectionMultiplexer 的配置中注册所有哨点。
我可以使用此代码将我的客户端连接到哨兵:
var options = new ConfigurationOptions()
{
CommandMap = CommandMap.Sentinel,
EndPoints = { { IP, Port } },
AllowAdmin = true,
TieBreaker = "",
ServiceName = ServiceName,
SyncTimeout = 5000,
AbortOnConnectFail = true,
Ssl = false
};
var connection = ConnectionMultiplexer.Connect(options, Console.Out);
return connection;
一旦获得连接,我需要使用标准的 redis 方法访问缓存数据库,例如 SetString 和 getString...所以
db = conn.getDatabase();
db.getString(key);
db.setString(key, value);
此时我收到一条错误消息,指出“此操作已在命令映射中禁用,无法使用:SETEX”或 GET。
我想应该有一种方法可以向哨兵询问与当前主服务器的连接,但我找不到很多有用的代码示例。 谁能帮帮我?
【问题讨论】:
标签: c# caching redis stackexchange.redis redis-sentinel