# 第二阶段模块一 **Repository Path**: old_he/stage-2-module-1 ## Basic Information - **Project Name**: 第二阶段模块一 - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-12-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 第二阶段模块一 #### 步骤 1. 集群搭建步骤就是讲义中的步骤。 2. 扩容主要是下面三条命令: ./redis-cli --cluster add-node 192.168.80.122:7007 192.168.80.122:7001 ./redis-cli --cluster reshard 127.0.0.1:7007 ./redis-cli --cluster add-node 192.168.80.122:7008 192.168.80.122:7007 --cluster-slave --cluster-master-id 0335d83d215deb38f537b95760e0a08031xxxxxx 3. JedisCluster的使用也比较简单 ``` java public class RedisDemo { JedisCluster jedisCluster; public RedisDemo(){ Set set = new HashSet<>(); set.add(new HostAndPort("192.168.80.122",7001)); set.add(new HostAndPort("192.168.80.122",7002)); set.add(new HostAndPort("192.168.80.122",7003)); set.add(new HostAndPort("192.168.80.122",7004)); set.add(new HostAndPort("192.168.80.122",7005)); set.add(new HostAndPort("192.168.80.122",7006)); set.add(new HostAndPort("192.168.80.122",7007)); set.add(new HostAndPort("192.168.80.122",7008)); this.jedisCluster = new JedisCluster(set); } public void get(String key){ System.out.println(jedisCluster.get(key)); } public void set(String key, String value){ System.out.println(jedisCluster.set(key, value)); } public static void main(String[] args) { RedisDemo demo = new RedisDemo(); demo.get("name1"); demo.set("name1", "ccc"); demo.get("name1"); } } ```