csredis 博客

csRedisgit地址

csRedis3.2.1 Nuget地址 (在使用csredis3.2.1获取sentinel时产生运行时异常,调查问题最后发现是获取sentinel的s-down-time配置参数存在问题。在sentinel集群中并非每个sentinel都能获取到这个参数,获取不到就抛出异常了。)

https://yq.aliyun.com/articles/503938

修复csredis获取redis sentinel的问题

http://blog.bossma.cn/csharp/fix-csredis-get-redis-sentinel-problem/

/// <summary>
/// RedisSentinelManagerContext
/// </summary>
public class RedisSentinelManagerContext
{
/// <summary>
/// 哨兵默认端口
/// </summary>
private const int DefaultSentinelPort = ; /// <summary>
/// Redis哨兵配置地址
/// </summary>
private static readonly string RedisSentinelAddresses = ConfigurationHelper.AppSetting("redis.sentinelAddresses"); /// <summary>
/// Redis哨兵Master地址
/// </summary>
private static readonly string RedisMasterName = ConfigurationHelper.AppSetting("redis.masterName"); /// <summary>
/// Redis密码
/// </summary>
private static readonly string RedisPassword = ConfigurationHelper.AppSetting("redis.password"); /// <summary>
/// RedisSentinelManager实例
/// </summary>
private static RedisSentinelManager _instance; /// <summary>
/// RedisSentinelManager实例
/// </summary>
public static RedisSentinelManager Instance()
{
if (_instance == null)
{
if (string.IsNullOrEmpty(RedisSentinelAddresses) || string.IsNullOrEmpty(RedisMasterName))
{
throw new Exception("没有配置Redis的哨兵地址或Master名称");
} var param = new string[];
_instance = new RedisSentinelManager(param);
RedisSentinelAddresses.Split(',').ForEach(p =>
{
var arr = p.Split(':');
_instance.Add(arr[], arr.Length >= ? int.Parse(arr[]) : DefaultSentinelPort);
});
if(!string.IsNullOrEmpty(RedisPassword))
_instance.Connected += (s, e) => _instance.Call(x => x.Auth(RedisPassword));
_instance.Connect(RedisMasterName);
} return _instance;
} public static string StringSet(string key, string value, int seconds)
{
return _instance.Call(r => r.Set(key, value, seconds));
} public static string StringSet(string key, string value, TimeSpan ts)
{
return _instance.Call(r => r.Set(key, value, ts));
} public static string StringGet(string key)
{
return _instance.Call(r => r.Get(key));
} public static bool KeyExpire(string key, int seconds)
{
return _instance.Call(r => r.Expire(key, seconds));
}
public static bool KeyExpire(string key, TimeSpan expiration)
{
return _instance.Call(r => r.Expire(key, expiration));
} public static bool KeyExist(string key)
{
return _instance.Call(r => r.Exists(key));
} public static bool HSet(string key, string field, object value)
{
return _instance.Call(r => r.HSet(key, field, value));
}
public static string HMSet(string key, Dictionary<string, string> dict)
{
return _instance.Call(r => r.HMSet(key, dict));
} public static Dictionary<string, string> HGetAll(string key)
{
return _instance.Call(r => r.HGetAll(key));
} public static string HGet(string key, string field)
{
return _instance.Call(r => r.HGet(key, field));
} public static bool HExists(string key, string field)
{
return _instance.Call(r => r.HExists(key, field));
} public static long HDel(string key, params string[] fields)
{
return _instance.Call(r => r.HDel(key, fields));
}
}

.Net支持Redis哨兵模式的更多相关文章

  1. [Redis] Redis哨兵模式部署 - zz胖的博客

    1. 部署Redis集群 redis的安装及配置参考[redis部署] 本文以创建一主二从的集群为例. 1.1 部署与配置 先创建sentinel目录,在该目录下创建8000,8001,8002三个以 ...

  2. Redis 哨兵模式(Sentinel)

    上一篇我们介绍了 redis 主从节点之间的数据同步复制技术,通过一次全量复制和不间断的命令传播,可以达到主从节点数据同步备份的效果,一旦主节点宕机,我们可以选择一个工作正常的 slave 成为新的主 ...

  3. Redis哨兵模式主从同步不可以绑定127.0.0.1或者0.0.0.0,不然无法进行主从同步

    Redis哨兵模式主从同步不可以绑定127.0.0.1或者0.0.0.0,不然无法进行主从同步,一定要绑定内网IP,而对于跨机房的问题,可以使用iptables进行nat转发来解决.

  4. Redis哨兵模式大key优化

    目前,Redis哨兵模式,内存资源有限,有很多key大于500M,性能待优化.需要迁移至Redis-cluster集群中.        涉及到的key如下: 0,hash,duser_record, ...

  5. Springboot2.x集成Redis哨兵模式

    Springboot2.x集成Redis哨兵模式 说明 Redis哨兵模式是Redis高可用方案的一种实现方式,通过哨兵来自动实现故障转移,从而保证高可用. 准备条件 pom.xml中引入相关jar ...

  6. Spring Boot 入门(十):集成Redis哨兵模式,实现Mybatis二级缓存

    本片文章续<Spring Boot 入门(九):集成Quartz定时任务>.本文主要基于redis实现了mybatis二级缓存.较redis缓存,mybaits自带缓存存在缺点(自行谷歌) ...

  7. 搭建redis哨兵模式

    搭建redis哨兵模式,一主两从三哨兵   1.从官网下载redis安装包:此处是redis-5.0.7.tar.gz 2.上传到目录 /utxt/soft 3.解压 4.cd /utxt/soft/ ...

  8. Redis哨兵模式的配置

    绪论 现有三台设备,192.168.137.11.192.168.137.12和192.168.137.13,要求在三台设备上实现redis哨兵模式,其中192.168.137.11为master,其 ...

  9. Redis哨兵模式(sentinel)学习总结及部署记录(主从复制、读写分离、主从切换)

    Redis的集群方案大致有三种:1)redis cluster集群方案:2)master/slave主从方案:3)哨兵模式来进行主从替换以及故障恢复. 一.sentinel哨兵模式介绍Sentinel ...

随机推荐

  1. Docker学习笔记_创建和使用Centos容器

    实验:创建和使用Centos容器 步骤: 1.搜索                                                     sudo docker search cen ...

  2. EXE DLL等可执行程序添加版本号版权等信息

    在使用Microsoft Visual Studio开发工具等编写的exe或者dll等可执行文件时,我们往往需要对这些可执行文件添加版本号,公司,版权等信息. 1. 在我们需要添加各种信息的项目工程中 ...

  3. ssh -X前设置DISPLAY=localhost:0

    如果是在windows上用XMing做XServer,前面的localhost不能省,否则会被当作一个unix domain socket,而XMing没有实现这个功能,所以会出错 connect / ...

  4. JSTL标签之core标签的使用

    参考:http://blog.csdn.net/qq_25827845/article/details/53311722 核心标签库的导入 <%@ taglib prefix="c&q ...

  5. 简单Factory模式

    #pragma once #include "student.h" #include "Teacher.h" typedef enum _EPersonType ...

  6. IDEA小技巧:添加代码快捷方式

    非常怀恋eclipse的的代码快捷方式tryc,今天给IDEA也添加了一个

  7. IE浏览器和Firefox浏览器兼容性问题及解决办法

    IE浏览器和Firefox浏览器兼容性问题及解决办法 为了方便大家阅读代码,以下以 IE 代替 Internet Explorer,以 MF/FF 代替 Mozzila Firefox : 1.//w ...

  8. Django实战之古风博客

    感谢 感谢杨青 大大的古风模板,设计的很棒,给个赞. 如有侵权,请联系我 运行环境 python3.6 Django==1.11.4 django-ckeditor==5.4.0 django-js- ...

  9. SQL 全角半角转换-(摘抄)

    /****** SQL转换全角/半角函数 开始******/ CREATE FUNCTION ConvertWordAngle ( @str NVARCHAR(4000), --要转换的字符串 @fl ...

  10. ZED 常用资料汇总

    Calibration file Location: /usr/local/zed/settings/SN10027507.conf I suggest the calibration file sh ...