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. python 输入参数解包,模块导入,接收IO输入参数

    #coding=utf-8 from sys import argv script,first,second,third = argv print "the script is=" ...

  2. 面试题:HTTP必知必会——常见面试题总结 背1

    1.常用的HTTP方法有哪些?GET: 用于请求访问已经被URI(统一资源标识符)识别的资源,可以通过URL传参给服务器POST:用于传输信息给服务器,主要功能与GET方法类似,但一般推荐使用POST ...

  3. django: rest-framework的 分页和过滤

    django: rest-framework的 分页和过滤 2018年06月28日 10:09:01 weixin_42359464 阅读数:136 标签: flaskrestframeworkdja ...

  4. 浏览器访问www.meituan.com过程

    “从浏览器输入 xxx 到跳转完成的过程发生了什么”,是一个常见的比较综合的面试题,以下是我查阅了一些资料后总结的,如有错误,还望批评指正.(以美团网为例) 1.在浏览器地址栏输入:meituan.c ...

  5. Linux 的文件系统

    Linux 文件属性 文件属性示意图 第一栏代表这个文件的类型与权限(permission): FHS Filesystem Hierarchy Standard(文件系统层次化标准) 1. / (r ...

  6. Convert HTML to PDF with New Plugin

    FROM:http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-with-N ...

  7. document.domain 跨域问题

    document.domain用来得到当前网页的域名. 比如在地址栏里输入:javascript:alert(document.domain); //www.315ta.com我们也可以给docume ...

  8. 注册 asp.net IIS

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319/aspnet_regiis.exe -i

  9. hibernate的几个重要的类和接口

    Configuration类 该类的对象会自动加载hibernate.cfg.xml文件,同时也可以定义自己的配置文件 sessionFactory接口 由于SessionFactory是重量级的,也 ...

  10. HTML <area> 标签区域map标签

    1.距形:(左上角顶点坐标为(x1,y1),右下角顶点坐标为(x2,y2)) <area shape="rect" coords="x1,y1,x2,y2" ...