Java中Redis的主从复制

package cn.e3mall.common.RedisText;

import redis.clients.jedis.Jedis;

/**
 * @author Mr.Li
 * @version 1.0
 * @Description:
 * @Modified By:
 * @date 2019/1/29 14:48
 */
public class TextMS {

    public static void main(String[] args) {
        Jedis jedis_M = new Jedis("127.0.0.1",6379);
        Jedis jedis_S = new Jedis("127.0.0.1",6380);

        //从机连接到主机
        jedis_S.slaveof("127.0.0.1",6379);

        //主机写入
        jedis_M.set("class","1122");

        //从机读取
        String result = jedis_S.get("class");
        System.out.println(result);
    }
}

 

你可能感兴趣的:(Redis)