java.lang.Object
org.springframework.data.redis.connection.RedisNode
All Implemented Interfaces:
NamedNode
Direct Known Subclasses:
RedisClusterNode, RedisServer

public class RedisNode extends Object implements NamedNode
Since:
1.4
Author:
Christoph Strobl, Thomas Darimont, Mark Paluch, LeeHyungGeol
  • Field Details

  • Constructor Details

    • RedisNode

      public RedisNode(String host, int port)
      Creates a new RedisNode with the given host, port.
      Parameters:
      host - must not be null
      port -
    • RedisNode

      protected RedisNode()
  • Method Details

    • fromString

      public static RedisNode fromString(String hostPortString)
      Parse a hostAndPort string into RedisNode. Supports IPv4, IPv6, and hostname notations including the port. For example:
       RedisNode.fromString("127.0.0.1");
       RedisNode.fromString("127.0.0.1:6379");
       RedisNode.fromString("[aaaa:bbbb::dddd:eeee]");
       RedisNode.fromString("[aaaa:bbbb::dddd:eeee]:6379");
       RedisNode.fromString("my.redis.server");
       RedisNode.fromString("my.redis.server:6379");
       
      Parameters:
      hostPortString - must not be null or empty.
      Returns:
      the parsed RedisNode.
      Since:
      2.7.4
    • fromString

      public static RedisNode fromString(String hostPortString, int defaultPort)
      Parse a hostAndPort string into RedisNode. Supports IPv4, IPv6, and hostname notations including the port. For example:
       RedisNode.fromString("127.0.0.1");
       RedisNode.fromString("127.0.0.1:6379");
       RedisNode.fromString("[aaaa:bbbb::dddd:eeee]");
       RedisNode.fromString("[aaaa:bbbb::dddd:eeee]:6379");
       RedisNode.fromString("my.redis.server");
       RedisNode.fromString("my.redis.server:6379");
       
      Parameters:
      hostPortString - must not be null or empty.
      Returns:
      the parsed RedisNode.
      Since:
      3.4
    • getHost

      public @Nullable String getHost()
      Returns:
      can be null.
    • getRequiredHost

      public String getRequiredHost()
      Returns the required host of this Redis Node or throws IllegalStateException if no host is set.
      Returns:
      Throws:
      IllegalStateException - if no host is associated with this Redis Node.
      Since:
      4.0
    • hasValidHost

      public boolean hasValidHost()
      Returns:
      whether this node has a valid host (not null and not empty).
      Since:
      2.3.8
    • getPort

      public @Nullable Integer getPort()
      Returns:
      can be null.
    • getPortOr

      public int getPortOr(int defaultPort)
      Returns the port of this Redis Node the defaultPort if no port is set.
      Returns:
      Since:
      4.0
    • getRequiredPort

      public int getRequiredPort()
      Returns the required port of this Redis Node or throws IllegalStateException if no port is set.
      Returns:
      Throws:
      IllegalStateException - if no host is associated with this Redis Node.
      Since:
      4.0
    • asString

      public String asString()
    • getName

      public @Nullable String getName()
      Specified by:
      getName in interface NamedNode
      Returns:
      the node name. Can be null.
    • setName

      public void setName(@Nullable String name)
    • getMasterId

      public @Nullable String getMasterId()
      Returns:
      can be null.
      Since:
      1.7
    • getId

      public @Nullable String getId()
      Returns:
      can be null.
      Since:
      1.7
    • setId

      public void setId(String id)
      Parameters:
      id -
      Since:
      1.7
    • getType

      public @Nullable RedisNode.NodeType getType()
      Returns:
      can be null.
      Since:
      1.7
    • isMaster

      public boolean isMaster()
      Returns:
      Since:
      1.7
    • isReplica

      public boolean isReplica()
      Returns:
      Since:
      2.1
    • newRedisNode

      public static RedisNode.RedisNodeBuilder newRedisNode()
      Returns:
      never null.
      Since:
      1.7
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object