redis.clients.jedis.JedisClusterInfoCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis Show documentation
Show all versions of jedis Show documentation
Jedis is a blazingly small and sane Redis java client.
package redis.clients.jedis;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.exceptions.JedisClusterOperationException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.jedis.util.SafeEncoder;
public class JedisClusterInfoCache {
private final Map nodes = new HashMap<>();
private final ConnectionPool[] slots = new ConnectionPool[Protocol.CLUSTER_HASHSLOTS];
private final HostAndPort[] slotNodes = new HostAndPort[Protocol.CLUSTER_HASHSLOTS];
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
private final Lock r = rwl.readLock();
private final Lock w = rwl.writeLock();
private final Lock rediscoverLock = new ReentrantLock();
private final GenericObjectPoolConfig poolConfig;
private final JedisClientConfig clientConfig;
private final Set startNodes;
private static final int MASTER_NODE_INDEX = 2;
public JedisClusterInfoCache(final JedisClientConfig clientConfig, final Set startNodes) {
this(clientConfig, null, startNodes);
}
public JedisClusterInfoCache(final JedisClientConfig clientConfig,
final GenericObjectPoolConfig poolConfig, final Set startNodes) {
this.poolConfig = poolConfig;
this.clientConfig = clientConfig;
this.startNodes = startNodes;
}
public void discoverClusterNodesAndSlots(Connection jedis) {
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy