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的下载.安装参 ...
随机推荐
- Nginx+tomcat+redis集群共享session实现负载均衡
1.nginx是一款轻量级兼备高性能的Http和反向代理服务器.所谓反向代理就是指用户发起访问请求,由代理服务器接受,然后将请求转发给正式服务器,并且将正式服务器处理完的数据返回给客户单,此时代理服务 ...
- spring笔记二
DI—Dependency Injection,即“依赖注入”:组件之间依赖关系由容器在运行期决定,形象的说,即由容器动态的将某个依赖关系注入到组件之中.依赖注入的目的并非为软件系统带来更多功能,而是 ...
- window+kafka
window环境搭建zookeeper,kafka集群 为了演示集群的效果,这里准备一台虚拟机(window 7),在虚拟机中搭建了单IP多节点的zookeeper集群(多IP节点的也是同理的),并且 ...
- ECharts饼图制作分析
ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11 ...
- [CF409F]000001
题目大意:输入一个数,输出一个数(愚人节系列) 题解:$OEIS$的$A000001$(原来我不想写的,但是洛谷的智能推荐推荐我做这个...是不是我太菜了) 卡点:无 C++ Code: #inclu ...
- [Leetcode] Best time to buy and sell stock 买卖股票的最佳时机
Say you have an array for which the i th element is the price of a given stock on day i. If you were ...
- CentOS 6通过yum升级Git
By francis_hao Mar 9,2017 在一个新机器上推送代码到github上时出现了下面的问题 error: The requested URL returned error: ...
- C# Async await和Task的关系
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 洛谷P1346 电车
P1346 电车 236通过 757提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 解不好啊,快疯了!!哪位大… 求解:为何除了-1的点之 ...
- python并发进程
1 引言 2 创建进程 2.1 通过定义函数的方式创建进程 2.2 通过定义类的方式创建进程 3 Process中常用属性和方法 3.1 守护进程:daemon 3.2 进程终结于存活检查:termi ...