侧边栏

针对net core 使用CSRedis 操作redis的三种连接实例方式

1、主从访问

 

 

2、哨兵模式

 

 

3、集群访问

 ConfigurationOptions sentinelOptions = new ConfigurationOptions();
            sentinelOptions.EndPoints.Add("180.76.*.*", 26379);
            sentinelOptions.EndPoints.Add("180.76.*.*", 26380);
            sentinelOptions.EndPoints.Add("180.76.*.*", 26381);
            sentinelOptions.TieBreaker = "";
            sentinelOptions.CommandMap = CommandMap.Sentinel;
            sentinelOptions.AbortOnConnectFail = false;
            // Connect!
            ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.Connect(sentinelOptions);

            // Get a connection to the master
            ConfigurationOptions redisServiceOptions = new ConfigurationOptions();
            redisServiceOptions.ServiceName = "mymaster1";   //master名称
            redisServiceOptions.Password = "redis_pwd";     //master访问密码
            redisServiceOptions.AbortOnConnectFail = true;
            ConnectionMultiplexer masterConnection = sentinelConnection.GetSentinelMasterConnection(redisServiceOptions);

            var db  = masterConnection.GetDatabase();
            var value= db.StringGet("testKey");
            Console.WriteLine($"[Use StackExchange-Redis] The remote redis-sentinel test key value:{
posted @   我有我的骄傲  阅读(515)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示