Redis master and slave

21ca發表於2017-03-16
1. Download Redis zip package for Windows: https://github.com/ServiceStack/redis-windows

2. Copy redis.windos.conf to master.conf and slave.conf.

3. master.conf
    port: 6379

4. slave.conf
   port: 6378
    slaveof 127.0.0.1 6379

5. Start Redis
    redis-server.exe master.conf
    redis-server.exe slave.conf

6. Write to master and read from slave:
  1. public class RedisTest {
  2.     public static void main(String[] args) {
  3.         Jedis master = new Jedis("127.0.0.1", 6379);
  4.         Jedis slave = new Jedis("127.0.0.1", 6378);

  5.         master.set("name", "test");
  6.         
  7.         System.out.println(master.get("name"));
  8.         System.out.println(slave.get("name"));
  9.         
  10.         master.close();
  11.         slave.close();
  12.     }
  13. }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10742815/viewspace-2135456/,如需轉載,請註明出處,否則將追究法律責任。

相關文章