Class JedisCluster

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class JedisCluster
    extends UnifiedJedis
    JedisCluster compatibility wrapper that extends UnifiedJedis for cluster operations. This class provides the traditional JedisCluster API while using the unified interface underneath.
    • Field Detail

      • INIT_NO_ERROR_PROPERTY

        public static final java.lang.String INIT_NO_ERROR_PROPERTY
        See Also:
        Constant Field Values
      • DEFAULT_TIMEOUT

        public static final int DEFAULT_TIMEOUT
        Default timeout in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_ATTEMPTS

        public static final int DEFAULT_MAX_ATTEMPTS
        Default amount of attempts for executing a command
        See Also:
        Constant Field Values
    • Constructor Detail

      • JedisCluster

        public JedisCluster​(HostAndPort node)
        Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.

        Here, the default timeout of 2000 ms is being used with 5 maximum attempts.

        Parameters:
        node - Node to first connect to.
      • JedisCluster

        public JedisCluster​(HostAndPort node,
                            int timeout)
        Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.

        Here, the default timeout of 2000 ms is being used with 5 maximum attempts.

        Parameters:
        node - Node to first connect to.
        timeout - connection and socket timeout in milliseconds.
      • JedisCluster

        public JedisCluster​(HostAndPort node,
                            int timeout,
                            int maxAttempts)
        Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.
        You can specify the timeout and the maximum attempts.
        Parameters:
        node - Node to first connect to.
        timeout - connection and socket timeout in milliseconds.
        maxAttempts - maximum attempts for executing a command.
      • JedisCluster

        public JedisCluster​(HostAndPort node,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
      • JedisCluster

        public JedisCluster​(HostAndPort node,
                            int timeout,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
      • JedisCluster

        public JedisCluster​(HostAndPort node,
                            int timeout,
                            int maxAttempts,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes)
        Creates a JedisCluster with multiple entry points.

        Here, the default timeout of 2000 ms is being used with 5 maximum attempts.

        Parameters:
        nodes - Nodes to connect to.
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes,
                            int timeout)
        Creates a JedisCluster with multiple entry points.

        Here, the default timeout of 2000 ms is being used with 5 maximum attempts.

        Parameters:
        nodes - Nodes to connect to.
        timeout - connection and socket timeout in milliseconds.
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes,
                            int timeout,
                            int maxAttempts)
        Creates a JedisCluster with multiple entry points.
        You can specify the timeout and the maximum attempts.
        Parameters:
        nodes - Nodes to connect to.
        timeout - connection and socket timeout in milliseconds.
        maxAttempts - maximum attempts for executing a command.
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes,
                            int timeout,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
      • JedisCluster

        public JedisCluster​(java.util.Set<HostAndPort> nodes,
                            int timeout,
                            int maxAttempts,
                            org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
    • Method Detail

      • getClusterNodes

        public java.util.Map<java.lang.String,​ConnectionPool> getClusterNodes()
        Returns all nodes that were configured to connect to in key-value pairs (Map).
        Key is the HOST:PORT and the value is the connection pool.
        Returns:
        the map of all connections.
      • getConnectionFromSlot

        public Connection getConnectionFromSlot​(int slot)
        Returns the connection for one of the 16,384 slots.
        Parameters:
        slot - the slot to retrieve the connection for.
        Returns:
        connection of the provided slot.