Class Node

java.lang.Object
com.reve.redis.cluster.Node

public class Node extends Object
This is a Cluster node. A redis cluster can have multiple nodes. A node can be master or a slave, which is defined inside flags variable. The node is connected/disconnected can be found from flags.
  • Constructor Details

    • Node

      public Node(String info)
      Creates a node from string information
      Parameters:
      info - contains all the information for a node, a sample can be like 38c462c95e2e1e5c54d8b5aa9a1e4dea65a3a1c1 127.0.0.1:7000@17000 myself,master - 0 1634017480000 21 connected 0-5460 or 17d577b8bc51e7aa581ddfdd1a0b656c802a007c 127.0.0.1:7003@17003 slave d9ed0b2319a15da00277cba0dacb8ebd6c686a62 0 1634017481000 20 connected "nodeID hostAddress:hostPort@hostPort2 flags masterNodeId lastPendingPingTime lastPongReceivedTime configurationEpoch status slotServed"
  • Method Details

    • getHostIpPort

      public String getHostIpPort()
      Returns:
      HostAddress:hostPort can be used to identify location of the node
    • getHostIp

      public String getHostIp()
    • getHostPort

      public int getHostPort()
    • setConnection

      public void setConnection(redis.clients.jedis.ConnectionPool connection)
      Set the connection pool for this node.
      Parameters:
      connection - connection pool for this node.
    • getConnection

      public redis.clients.jedis.Connection getConnection()
      Get a jedis connection from connection pool.
      Returns:
      a connection from connection pool
    • isMaster

      public boolean isMaster()
      Returns:
      true if it is a master otherwise false
    • toString

      public String toString()
      Implementation of to string method
      Overrides:
      toString in class Object
    • getNextFreeSlotKey

      public String getNextFreeSlotKey() throws IllegalAccessException
      Only master node serves slot, so if this Node is a master it will return slot key that points to this node.
      Returns:
      a free slot key
      Throws:
      IllegalAccessException - if this node is a slave.
    • getSlotKeyForTable

      public String getSlotKeyForTable(String tableName) throws IllegalAccessException
      If it is aimed that each table should use a unique slot key, this method ensure a fixed slot key for specified table
      Parameters:
      tableName - Name of the database table slot key needed for
      Returns:
      Slot key
      Throws:
      IllegalAccessException
    • saveSlotKeyIfMine

      public void saveSlotKeyIfMine(String tableName, String slotKey)
      This method checks if the given slot key belongs to this node. If it does, then it will map this Slot key with the given tableName in this node.
      Parameters:
      tableName - The name of the table this slot key has been used.
      slotKey - The slot key that has been used.