redis

一、连接redis集群

1.范式

JedisCluster jedisCluster;
Set<HostAndPort>  jedisClusterNodes = new HashSet<HostAndPort>();
String host = "10.128.113.68";
jedisClusterNodes.add(new HostAndPort(host,port_1));
jedisClusterNodes.add(new HostAndPort(host,port_2));
jedisClusterNodes.add(new HostAndPort(host,port_3));
jedisCluster = new JedisCluster(Set<HostAndPort> jedisClusterNodes , int timeout, int maxAttempts);

2.问题

jedis
  • java.lang.NumberFormatException: For input string: "6380@16380"

原因分析
redis.clients>>jedis版本未匹配redis集群版本。

<!-- redis -->
<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>2.9.0</version>
</dependency>
大key

生产环境会有size很大的key(流量排行的 “sorted set”)

  • 在删除大key时,会造成redis集群同当前key所在节点通信超时,当前节点显示"connection failed "
  • 在线迁移slot,保存大key的slot会长时间都处于import状态和migrate状态之间,造成迁移超时,节点异常。
    解决方案,更新redis-trib.rb脚本的"def reshard_cluster_cmd(argv,opt)"
    移动光标到" print "Do you want to proceed with the proposed reshard plan (yes/no)? " ",更新code,
if !opt['yes']
    print "Do you want to proceed with the proposed reshard plan (yes/no)? "
    yesno = STDIN.gets.chop
    exit(1) if (yesno != "yes")
end
reshard_table.each{|e|
xputs "------------------------> #{e[:slot]}"
case e[:slot]
    when 7269
        puts "pass 7269"
    else
        move_slot(e[:source],target,e[:slot],
                :dots=>true,
                :pipeline=>opt['pipeline'])
end
}

二、常用command

1.测试redis性能。

redis-benchmark -h [ip] -p [port] -n [message num]

三、redis数据规范设计

  1. 当数据量很大,要精简key的长度。
  2. redis集群越大,通过增加机器来扩大集群容量的价格越高。

排行需求

背景

sorted set保存排行榜(1.4亿个元素)。

两个问题
  • 关于delete redis的大key。删除大key造成redis长时间阻塞和一台master down机。
  • redis数据存储不均衡。
解决方案(未实施)
  • redis数据存储不均衡。
    • 迁移slot。
    • 对排行榜做分区。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值