您的位置:首页 > 数据库 > Redis

Redis cluster on Windows

2017-08-09 10:02 239 查看
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:

public static void main(String[] args) throws Exception {

        Set<HostAndPort> nodes = new HashSet<HostAndPort>();

        nodes.add(new HostAndPort("127.0.0.1", 7001));

        nodes.add(new HostAndPort("127.0.0.1", 7002));

        nodes.add(new HostAndPort("127.0.0.1", 7003));

        nodes.add(new HostAndPort("127.0.0.1", 7004));

        nodes.add(new HostAndPort("127.0.0.1", 7005));

        nodes.add(new HostAndPort("127.0.0.1", 7006));

        JedisCluster cluster = new JedisCluster(nodes );

        

        cluster.set("a", "1");

        System.out.println(cluster.get("a"));

        cluster.close();

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: