Redis的cluster集群
public class RedisShardPoolTest { static ShardedJedisPool pool; static { JedisPoolConfig config = new JedisPoolConfig();// Jedis池配置 config.setMaxActive();// 最大活动的对象个数 config.setMaxIdle( * );// 对象最大空闲时间 config.setMaxWait( * );// 获取对象时最大等待时间 config.setTestOnBorrow(true); String hostA = "127.0.0.1"; int portA = ; String hostB = "127.0.0.1"; int portB = ; List<JedisShardInfo> jdsInfoList = new ArrayList<JedisShardInfo>(); JedisShardInfo infoA = new JedisShardInfo(hostA, portA); infoA.setPassword("testpass"); JedisShardInfo infoB = new JedisShardInfo(hostB, portB); infoB.setPassword("testpass"); jdsInfoList.add(infoA); jdsInfoList.add(infoB); pool = new ShardedJedisPool(config, jdsInfoList, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN); } /**
*
* @param args
*
*/ public static void main(String[] args) { for (int i = ; i < ; i++) { String key = generateKey();
ShardedJedis jds = null; try {
jds = pool.getResource(); System.out.println(key + ":"
+ jds.getShard(key).getClient().getHost());
System.out.println(key + ":"
+ jds.getShard(key).getClient().getPort()); System.out.println(jds.get(key));
System.out.println(jds.set(key,""));
} catch (Exception e) {
e.printStackTrace();
}
finally {
pool.returnResource(jds); }
}
} private static int index = ; public static String generateKey() { return String.valueOf(Thread.currentThread().getId()) + "_" + (index++); } }
从运行结果中可以看到,不同的key被分配到不同的Redis-Server上去了。
附件是一份windows下redis服务端程序和客户端需要的jar包,附件下载后后缀改为.rar后解压缩
可以自己配置分布式和主从测试,
配置文件着重关注以下配置
服务端口和 绑定网卡IP
# Accept connections on the specified port, default is 6379
port 6178
# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for connections.
#
# bind 127.0.0.1
是否为备机(IP:端口)
################################# REPLICATION #################################
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
slaveof 127.0.0.1 6378
认证密码
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
最好深读官方的解决方案http://redis.io/topics/partitioning
Redis的cluster集群的更多相关文章
- Redis进阶实践之十一 Redis的Cluster集群搭建
一.引言 本文档只对Redis的Cluster集群做简单的介绍,并没有对分布式系统的详细概念做深入的探讨.本文只是提供了有关如何设置集群.测试和操作集群的说明,而不涉及Redis集群规范中涵 ...
- Redis进阶实践之十二 Redis的Cluster集群动态扩容
一.引言 上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cl ...
- Redis搭建(七):Redis的Cluster集群动态增删节点
一.引言 上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cluste ...
- redis之(十七)自己实现redis的cluster集群环境的搭建
[一]创建不同节点的配置文件和目录.并将配置文件中的port,cluster-enable,daemonize项做修改. --->port:修改成redis实例对应的端口号 --->clu ...
- Azure Redis Cache (5) Redis Cache Cluster集群模式
<Windows Azure Platform 系列文章目录> Redis Cluster 3.0之后的版本,已经支持Redis Cluster集群模式,Redis Cluster采用无中 ...
- redis之(十六)redis的cluster集群环境的搭建,转载
最近redis已经比较火了,有关redis的详细介绍,网上有一大堆,我这里只作简单的介绍,然后跟大家一起学习Redis Cluster 3.0的搭建与使用.Redis是一款开源的.网络化的.基于内存的 ...
- redis之cluster(集群)
搭建redis cluster 1. 准备节点 2. 节点间的通信 3. 分配槽位给节点 redis-cluster架构 多个服务端,负责读写,彼此通信,redis指定了16384个槽. 多匹马儿,负 ...
- 【Redis】Redis cluster集群搭建
Redis集群基本介绍 Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施installation. Redis 集群不支持那些需要同时处理多个键的 Redis 命令, 因为执行 ...
- Redis Cluster 集群搭建与扩容、缩容
说明:仍然是伪集群,所有的Redis节点,都在一个服务器上,采用不同配置文件,不同端口的形式实现 前提:已经安装好了Redis,本文的redis的版本是redis-6.2.3 Redis的下载.安装参 ...
随机推荐
- lintcode-108-分割回文串 II
108-分割回文串 II 给定一个字符串s,将s分割成一些子串,使每个子串都是回文. 返回s符合要求的的最少分割次数. 样例 比如,给出字符串s = "aab", 返回 1, 因为 ...
- LTE 中基于X2的切换
LTE 中基于X2的切换 (36.300, 23.401)SGW 保持不变 http://blog.sina.com.cn/s/blog_673b30dd0100j4pe.html 1:eNod ...
- Eclipse下JRebel6.5.0热部署插件安装、破解及配置
发现一个问题:如果安装了jRebel,但是并未对项目添加jRebel监听时,如果重写jar包中的类, 虽然重写后的类会得到编译(classes中的class已经是修改后的class),但是并不会调用重 ...
- Intellij Idea 创建Web项目入门
相关软件: Intellij Idea14:http://pan.baidu.com/s/1nu16VyD JDK7:http://pan.baidu.com/s/1dEstJ5f Tomcat(ap ...
- PHP判断类型的方法
1.gettype():获取变量类型 2.is_array():判断变量类型是否为数组类型 3.is_double():判断变量类型是否为倍浮点类型 4.is_float():判断变量类型是否为浮点类 ...
- PHP变量类型转换
PHP数据类型转换 PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: •(int).(integer):转换成整形 •(float).(double).(real):转换成浮点型 •(s ...
- 在submit_bio处使用stapn
想着在submit_bio的地方,发现在guru模式下,stap是经常性地把内核整挂呀,不得已,也没有发现stap什么比较好的调试方法,所以索性直接使用stap的语法了,但是发现有问题呢,有的时候bv ...
- c# 调用 matlab 引发初始化错误 异常
1. 除了matlab 编译的DLL 意外还需要引用 MWArray.dll 这个dill 在安装了 MCRInstaller.exe(matlab运行环境之后就会有了): 2. 最重要的一点.ne ...
- [剑指Offer] 30.连续子数组的最大和
题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...
- 输入的是util包下面的 时间, 接受的是java.sql.date 或者 java.util.date类型