Package com.reve.redis.cluster
Class Node
java.lang.Object
com.reve.redis.cluster.Node
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionredis.clients.jedis.ConnectionGet a jedis connection from connection pool.intOnly master node serves slot, so if thisNodeis a master it will return slot key that points to this node.getSlotKeyForTable(String tableName) If it is aimed that each table should use a unique slot key, this method ensure a fixed slot key for specified tablebooleanisMaster()voidsaveSlotKeyIfMine(String tableName, String slotKey) This method checks if the given slot key belongs to this node.voidsetConnection(redis.clients.jedis.ConnectionPool connection) Set the connection pool for this node.toString()Implementation of to string method
-
Constructor Details
-
Node
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
- Returns:
- HostAddress:hostPort can be used to identify location of the node
-
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
Implementation of to string method -
getNextFreeSlotKey
Only master node serves slot, so if thisNodeis 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
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
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.
-