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的下载.安装参 ...
随机推荐
- LTE中基于S1的切换
1:源eNodeB决定进行基于S1的切换.S1切换的原因可能是源eNodeB和目标eNodeB之间不存在X2连接,或者源eNodeB根据其他情况作出的判断. 2:源eNodeB向源MME发送Hando ...
- 玩转VFS(sys_open, overlayfs, rename)
带着问题学习dentry 1)文件删除时 dentry的结构是如何变化的?是直接设置无效的吗?如果此时正好有个访问是在要删除目录下的一个文件,这咋办呢? 2)内核document目录下级联式地使用 d ...
- 【Python】Python 模块一考核
1. #!/usr/bin/python 和#!/usr/bin/env python 含义 大部分python文件的头部都会写上 #!/usr/bin/python 或者 #!/usr/bin/e ...
- jdbc连接oracle语法
public class LangDemo { public static void main(String[] args) throws Exception{ try { //加载驱动 Class. ...
- Intellij IDEA将工程打包成jar包并执行
打开File -> Project Structure -> Artifacts 点击“+”,选择“Jar”,选择Empty或From modules with dependencies, ...
- JS调用C#中的变量
今天早上做项目,需要使用JS来得到数据库里面表的行数.经过查找资料,知道可以使用在C#中定义一个全局变量.在JS中调用即可,自己总结一下:供日后参考; public string Str() { st ...
- BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】
题目 Moving Pebbles Two players play the following game. At the beginning of the game they start with ...
- Bash 实例,第二部分
我们先看一下处理命令行自变量的简单技巧,然后再看看 bash 基本编程结构. 接收自变量 在 介绍性文章 中的样本程序中,我们使用环境变量 "$1" 来引用第一个命令行自变量.类似 ...
- hadoop之shuffle详解
Shuffle描述着数据从map task输出到reduce task输入的这段过程. 如map 端的细节图,Shuffle在reduce端的过程也能用图上标明的三点来概括.当前reduce copy ...
- 百练2505:A multiplication game
传送门:http://bailian.openjudge.cn/practice/2505/ [题解] 我们找找规律: 1~9显然是Stan wins. 10~18是Ollie wins. 19~16 ...