ITPub博客

首页 > 数据库 > MySQL > Redis cluster on Windows

Redis cluster on Windows

原创 MySQL 作者:21ca 时间:2017-03-16 14:07:36 0 删除 编辑
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/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Redis master and slave
下一篇: Redis sentinel
全部评论

注册时间:2009-03-24

  • 博文量
    58
  • 访问量
    91019