Class RedisURI.Builder

  • Enclosing class:
    RedisURI

    public static class RedisURI.Builder
    extends Object
    Builder for Redis URI.
    • Method Detail

      • socket

        public static RedisURI.Builder socket​(String socket)
        Set Redis socket. Creates a new builder.
        Parameters:
        socket - the host name
        Returns:
        new builder with Redis socket.
      • redis

        public static RedisURI.Builder redis​(String host)
        Set Redis host. Creates a new builder.
        Parameters:
        host - the host name
        Returns:
        new builder with Redis host/port.
      • redis

        public static RedisURI.Builder redis​(String host,
                                             int port)
        Set Redis host and port. Creates a new builder
        Parameters:
        host - the host name
        port - the port
        Returns:
        new builder with Redis host/port.
      • sentinel

        public static RedisURI.Builder sentinel​(String host)
        Set Sentinel host. Creates a new builder.
        Parameters:
        host - the host name
        Returns:
        new builder with Sentinel host/port.
      • sentinel

        public static RedisURI.Builder sentinel​(String host,
                                                int port)
        Set Sentinel host and port. Creates a new builder.
        Parameters:
        host - the host name
        port - the port
        Returns:
        new builder with Sentinel host/port.
      • sentinel

        public static RedisURI.Builder sentinel​(String host,
                                                String masterId)
        Set Sentinel host and master id. Creates a new builder.
        Parameters:
        host - the host name
        masterId - sentinel master id
        Returns:
        new builder with Sentinel host/port.
      • sentinel

        public static RedisURI.Builder sentinel​(String host,
                                                int port,
                                                String masterId)
        Set Sentinel host, port and master id. Creates a new builder.
        Parameters:
        host - the host name
        port - the port
        masterId - sentinel master id
        Returns:
        new builder with Sentinel host/port.
      • withSentinel

        public RedisURI.Builder withSentinel​(String host)
        Add a withSentinel host to the existing builder.
        Parameters:
        host - the host name
        Returns:
        the builder
      • withSentinel

        public RedisURI.Builder withSentinel​(String host,
                                             int port)
        Add a withSentinel host/port to the existing builder.
        Parameters:
        host - the host name
        port - the port
        Returns:
        the builder
      • withSentinel

        public RedisURI.Builder withSentinel​(String host,
                                             int port,
                                             CharSequence password)
        Add a withSentinel host/port and Sentinel authentication to the existing builder.
        Parameters:
        host - the host name
        port - the port
        password - the Sentinel password (supported since Redis 5.0.1)
        Returns:
        the builder
        Since:
        5.2
      • withSentinel

        public RedisURI.Builder withSentinel​(RedisURI redisURI)
        Add a withSentinel RedisURI to the existing builder.
        Parameters:
        redisURI - the sentinel URI
        Returns:
        the builder
        Since:
        5.2
      • withHost

        public RedisURI.Builder withHost​(String host)
        Adds host information to the builder. Does only affect Redis URI, cannot be used with Sentinel connections.
        Parameters:
        host - the port
        Returns:
        the builder
      • withPort

        public RedisURI.Builder withPort​(int port)
        Adds port information to the builder. Does only affect Redis URI, cannot be used with Sentinel connections.
        Parameters:
        port - the port
        Returns:
        the builder
      • withSsl

        public RedisURI.Builder withSsl​(RedisURI source)
        Apply authentication from another RedisURI. The SSL settings of the source URI will be applied to this URI. That is in particular SSL usage, peer verification and StartTLS.
        Parameters:
        source - must not be null.
        Returns:
        the builder
        Since:
        6.0
      • withSsl

        public RedisURI.Builder withSsl​(boolean ssl)
        Adds ssl information to the builder. Sets SSL also for already configured Redis Sentinel nodes.
        Parameters:
        ssl - true if use SSL
        Returns:
        the builder
      • withStartTls

        public RedisURI.Builder withStartTls​(boolean startTls)
        Enables/disables StartTLS when using SSL. Sets StartTLS also for already configured Redis Sentinel nodes.
        Parameters:
        startTls - true if use StartTLS
        Returns:
        the builder
      • withVerifyPeer

        public RedisURI.Builder withVerifyPeer​(boolean verifyPeer)
        Enables/disables peer verification. Sets peer verification also for already configured Redis Sentinel nodes.
        Parameters:
        verifyPeer - true to verify hosts when using SSL
        Returns:
        the builder
      • withVerifyPeer

        public RedisURI.Builder withVerifyPeer​(SslVerifyMode verifyMode)
        Configures peer verification mode. Sets peer verification also for already configured Redis Sentinel nodes.
        Parameters:
        verifyMode - the mode to verify hosts when using SSL
        Returns:
        the builder
        Since:
        6.1
      • withDatabase

        public RedisURI.Builder withDatabase​(int database)
        Configures the database number.
        Parameters:
        database - the database number
        Returns:
        the builder
      • withClientName

        public RedisURI.Builder withClientName​(String clientName)
        Configures a client name. Sets client name also for already configured Redis Sentinel nodes.
        Parameters:
        clientName - the client name
        Returns:
        the builder
      • withLibraryName

        public RedisURI.Builder withLibraryName​(String libraryName)
        Configures a library name. Sets library name also for already configured Redis Sentinel nodes.
        Parameters:
        libraryName - the library name
        Returns:
        the builder
        Since:
        6.3
      • withLibraryVersion

        public RedisURI.Builder withLibraryVersion​(String libraryVersion)
        Configures a library version. Sets library version also for already configured Redis Sentinel nodes.
        Parameters:
        libraryVersion - the library version
        Returns:
        the builder
        Since:
        6.3
      • withAuthentication

        public RedisURI.Builder withAuthentication​(String username,
                                                   CharSequence password)
        Configures authentication.
        Parameters:
        username - the user name
        password - the password name
        Returns:
        the builder
        Since:
        6.0
      • withAuthentication

        public RedisURI.Builder withAuthentication​(RedisURI source)
        Apply authentication from another RedisURI. The authentication settings of the source URI will be applied to this builder.
        Parameters:
        source - must not be null.
        Since:
        6.0
      • withAuthentication

        public RedisURI.Builder withAuthentication​(String username,
                                                   char[] password)
        Configures authentication. Empty password is supported (although not recommended for security reasons).
        Parameters:
        username - the user name
        password - the password name
        Returns:
        the builder
        Since:
        6.0
      • withAuthentication

        public RedisURI.Builder withAuthentication​(RedisCredentialsProvider credentialsProvider)
        Configures authentication.
        Parameters:
        credentialsProvider - must not be null.
        Since:
        6.2
      • withPassword

        @Deprecated
        public RedisURI.Builder withPassword​(String password)
        Deprecated.
        since 6.0. Use withPassword(CharSequence) or withPassword(char[]) to avoid String caching.
        Configures authentication. Empty password is supported (although not recommended for security reasons).

        This method is deprecated as of Lettuce 6.0. The reason is that String has a strong caching affinity and the JVM cannot easily GC String instances. Therefore, we suggest using either char[] or a custom CharSequence (e.g. StringBuilder or netty's AsciiString).

        Parameters:
        password - the password
        Returns:
        the builder
      • withPassword

        public RedisURI.Builder withPassword​(CharSequence password)
        Configures authentication. Empty password is supported (although not recommended for security reasons).
        Parameters:
        password - the password
        Returns:
        the builder
        Since:
        6.0
      • withPassword

        public RedisURI.Builder withPassword​(char[] password)
        Configures authentication. Empty password is supported (although not recommended for security reasons).
        Parameters:
        password - the password
        Returns:
        the builder
        Since:
        4.4
      • withTimeout

        public RedisURI.Builder withTimeout​(Duration timeout)
        Configures a timeout.
        Parameters:
        timeout - must not be null or negative.
        Returns:
        the builder
      • withSentinelMasterId

        public RedisURI.Builder withSentinelMasterId​(String sentinelMasterId)
        Configures a sentinel master Id.
        Parameters:
        sentinelMasterId - sentinel master id, must not be empty or null
        Returns:
        the builder
      • build

        public RedisURI build()
        Returns:
        the RedisURI.