JedisCluster 操作多节点

package com.example.redis.client.cluster;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

import java.util.Map;

@Service
public class MultiNodesOperation {

    @Autowired
    private JedisCluster jedisCluster;

    public void operateMultiNodes() {
        Map jedisPoolMap = jedisCluster.getClusterNodes();
        for (Map.Entry entry : jedisPoolMap.entrySet()) {
            Jedis jedis = entry.getValue().getResource();
            if (!isMaster(jedis)) {
                continue;
            }
            operate(jedis);
        }
    }

    private void operate(Jedis jedis) {
    }

    private boolean isMaster(Jedis jedis) {

        return false;
    }

}

你可能感兴趣的:(JedisCluster 操作多节点)