.NET CORE 3.1 + docker-compose + redis哨兵模式
redis哨兵模式参数
https://blog.csdn.net/weixin_41622183/article/details/86600515
.NET CORE调用示例代码:
1、基于StackExchange.Redis
ConfigurationOptions sentinelConfig = new ConfigurationOptions(); sentinelConfig.ServiceName = "mymaster"; sentinelConfig.EndPoints.Add("172.19.90.86", 26379); sentinelConfig.EndPoints.Add("172.19.90.86", 26380); sentinelConfig.EndPoints.Add("172.19.90.86", 26381); sentinelConfig.TieBreaker = ""; sentinelConfig.Password = ""; sentinelConfig.DefaultVersion = new Version(4, 0, 11); // its important to set the Sentinel commands supported sentinelConfig.CommandMap = CommandMap.Sentinel; // Get sentinel connection ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.SentinelConnect(sentinelConfig, Console.Out); // Create master service configuration ConfigurationOptions masterConfig = new ConfigurationOptions { ServiceName = "mymaster" }; // Get master Redis connection var redisMasterConnection = sentinelConnection.GetSentinelMasterConnection(masterConfig); IDatabase db = redisMasterConnection.GetDatabase(); db.StringSet("b", 2); string value1 = db.StringGet("b"); Console.WriteLine("Hello World!");
2、基于CSRedisClient
try { //连接哨兵 var csredis = new CSRedis.CSRedisClient("mymaster", new[] { "172.19.90.86:26379" }); //初始化 RedisHelper RedisHelper.Initialization(csredis); RedisHelper.Set("name", "祝雷");//设置值。默认永不过期 Console.WriteLine(RedisHelper.Get<String>("name")); } catch (Exception e) { }
浙公网安备 33010602011771号