Redis cluster on Windows

21ca發表於2017-03-16
1. Create new folder 'cluster' under redis-64.3.0.503. Create subfolder 7001 -7006 under the folder 'cluster'. Copy redis.windows.conf.
    redis
    |---7001/redis.conf
    |---7002/redis.conf
    |---7003/redis.conf
    |---7004/redis.conf
    |---7005/redis.conf
    |---7006/redis.conf

There are 3 master nodes and 3 slave nodes.

2. Update configuration in redis.conf
        port 7001
        cluster-enabled yes
        cluster-config-file nodes.conf

3. Download Ruby from http://rubyinstaller.org/downloads/. 
    Install redis dependency under ruby: gem install redis

4. Startup redis:
    cluster\7001>..\..\redis-server.exe redis.conf
    cluster\7002>..\..\redis-server.exe redis.conf
    cluster\7003>..\..\redis-server.exe redis.conf
    cluster\7004>..\..\redis-server.exe redis.conf
    cluster\7005>..\..\redis-server.exe redis.conf
    cluster\7006>..\..\redis-server.exe redis.conf

5. Setup cluster:
D:\Tools\ruby-2.3.3-x64-mingw32>bin\ruby.exe ..\redis-3.2.8\src\redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

Done.

Java client example:
  1. public static void main(String[] args) throws Exception {
  2.         Set<HostAndPort> nodes = new HashSet<HostAndPort>();
  3.         nodes.add(new HostAndPort("127.0.0.1", 7001));
  4.         nodes.add(new HostAndPort("127.0.0.1", 7002));
  5.         nodes.add(new HostAndPort("127.0.0.1", 7003));
  6.         nodes.add(new HostAndPort("127.0.0.1", 7004));
  7.         nodes.add(new HostAndPort("127.0.0.1", 7005));
  8.         nodes.add(new HostAndPort("127.0.0.1", 7006));
  9.         JedisCluster cluster = new JedisCluster(nodes );
  10.         
  11.         cluster.set("a", "1");
  12.         System.out.println(cluster.get("a"));
  13.         cluster.close();
  14.     }



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

相關文章