Class RedisClient

    • Constructor Detail

      • RedisClient

        protected RedisClient()
        Creates a uri-less RedisClient. You can connect to different Redis servers but you must supply a RedisURI on connecting. Methods without having a RedisURI will fail with a IllegalStateException. Non-private constructor to make RedisClient proxyable.
    • Method Detail

      • create

        public static RedisClient create​(RedisURI redisURI)
        Create a new client that connects to the supplied uri with default ClientResources. You can connect to different Redis servers but you must supply a RedisURI on connecting.
        Parameters:
        redisURI - the Redis URI, must not be null
        Returns:
        a new instance of RedisClient
      • create

        public static RedisClient create​(String uri)
        Create a new client that connects to the supplied uri with default ClientResources. You can connect to different Redis servers but you must supply a RedisURI on connecting.
        Parameters:
        uri - the Redis URI, must not be null
        Returns:
        a new instance of RedisClient
      • create

        public static RedisClient create​(ClientResources clientResources,
                                         String uri)
        Create a new client that connects to the supplied uri with shared ClientResources.You need to shut down the ClientResources upon shutting down your application. You can connect to different Redis servers but you must supply a RedisURI on connecting.
        Parameters:
        clientResources - the client resources, must not be null
        uri - the Redis URI, must not be null
        Returns:
        a new instance of RedisClient
      • create

        public static RedisClient create​(ClientResources clientResources,
                                         RedisURI redisURI)
        Create a new client that connects to the supplied uri with shared ClientResources. You need to shut down the ClientResources upon shutting down your application.You can connect to different Redis servers but you must supply a RedisURI on connecting.
        Parameters:
        clientResources - the client resources, must not be null
        redisURI - the Redis URI, must not be null
        Returns:
        a new instance of RedisClient
      • connect

        public StatefulRedisConnection<String,​String> connect()
        Open a new connection to a Redis server that treats keys and values as UTF-8 strings.
        Returns:
        A new stateful Redis connection
      • connect

        public <K,​V> StatefulRedisConnection<K,​V> connect​(RedisCodec<K,​V> codec)
        Open a new connection to a Redis server. Use the supplied codec to encode/decode keys and values.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        Returns:
        A new stateful Redis connection
      • connect

        public StatefulRedisConnection<String,​String> connect​(RedisURI redisURI)
        Open a new connection to a Redis server using the supplied RedisURI that treats keys and values as UTF-8 strings.
        Parameters:
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
      • connect

        public <K,​V> StatefulRedisConnection<K,​V> connect​(RedisCodec<K,​V> codec,
                                                                      RedisURI redisURI)
        Open a new connection to a Redis server using the supplied RedisURI and the supplied codec to encode/decode keys.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
      • connectAsync

        public <K,​V> ConnectionFuture<StatefulRedisConnection<K,​V>> connectAsync​(RedisCodec<K,​V> codec,
                                                                                             RedisURI redisURI)
        Open asynchronously a new connection to a Redis server using the supplied RedisURI and the supplied codec to encode/decode keys.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        redisURI - the Redis server to connect to, must not be null
        Returns:
        ConnectionFuture to indicate success or failure to connect.
        Since:
        5.0
      • connectPubSub

        public StatefulRedisPubSubConnection<String,​String> connectPubSub()
        Open a new pub/sub connection to a Redis server that treats keys and values as UTF-8 strings.
        Returns:
        A new stateful pub/sub connection
      • connectPubSub

        public StatefulRedisPubSubConnection<String,​String> connectPubSub​(RedisURI redisURI)
        Open a new pub/sub connection to a Redis server using the supplied RedisURI that treats keys and values as UTF-8 strings.
        Parameters:
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new stateful pub/sub connection
      • connectPubSub

        public <K,​V> StatefulRedisPubSubConnection<K,​V> connectPubSub​(RedisCodec<K,​V> codec)
        Open a new pub/sub connection to the Redis server using the supplied RedisURI and use the supplied codec to encode/decode keys and values.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        Returns:
        A new stateful pub/sub connection
      • connectPubSub

        public <K,​V> StatefulRedisPubSubConnection<K,​V> connectPubSub​(RedisCodec<K,​V> codec,
                                                                                  RedisURI redisURI)
        Open a new pub/sub connection to the Redis server using the supplied RedisURI and use the supplied codec to encode/decode keys and values.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
      • connectPubSubAsync

        public <K,​V> ConnectionFuture<StatefulRedisPubSubConnection<K,​V>> connectPubSubAsync​(RedisCodec<K,​V> codec,
                                                                                                         RedisURI redisURI)
        Open asynchronously a new pub/sub connection to the Redis server using the supplied RedisURI and use the supplied codec to encode/decode keys and values.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        redisURI - the redis server to connect to, must not be null
        Returns:
        ConnectionFuture to indicate success or failure to connect.
        Since:
        5.0
      • connectSentinel

        public StatefulRedisSentinelConnection<String,​String> connectSentinel()
        Open a connection to a Redis Sentinel that treats keys and values as UTF-8 strings.
        Returns:
        A new stateful Redis Sentinel connection
      • connectSentinel

        public <K,​V> StatefulRedisSentinelConnection<K,​V> connectSentinel​(RedisCodec<K,​V> codec)
        Open a connection to a Redis Sentinel that treats keys and use the supplied codec to encode/decode keys and values. The client RedisURI must contain one or more sentinels.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - Use this codec to encode/decode keys and values, must not be null
        Returns:
        A new stateful Redis Sentinel connection
      • connectSentinel

        public StatefulRedisSentinelConnection<String,​String> connectSentinel​(RedisURI redisURI)
        Open a connection to a Redis Sentinel using the supplied RedisURI that treats keys and values as UTF-8 strings. The client RedisURI must contain one or more sentinels.
        Parameters:
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
      • connectSentinel

        public <K,​V> StatefulRedisSentinelConnection<K,​V> connectSentinel​(RedisCodec<K,​V> codec,
                                                                                      RedisURI redisURI)
        Open a connection to a Redis Sentinel using the supplied RedisURI and use the supplied codec to encode/decode keys and values. The client RedisURI must contain one or more sentinels.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - the Redis server to connect to, must not be null
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
      • connectSentinelAsync

        public <K,​V> CompletableFuture<StatefulRedisSentinelConnection<K,​V>> connectSentinelAsync​(RedisCodec<K,​V> codec,
                                                                                                              RedisURI redisURI)
        Open asynchronously a connection to a Redis Sentinel using the supplied RedisURI and use the supplied codec to encode/decode keys and values. The client RedisURI must contain one or more sentinels.
        Type Parameters:
        K - Key type
        V - Value type
        Parameters:
        codec - the Redis server to connect to, must not be null
        redisURI - the Redis server to connect to, must not be null
        Returns:
        A new connection
        Since:
        5.1
      • newStatefulRedisConnection

        protected <K,​V> StatefulRedisConnectionImpl<K,​V> newStatefulRedisConnection​(RedisChannelWriter channelWriter,
                                                                                                PushHandler pushHandler,
                                                                                                RedisCodec<K,​V> codec,
                                                                                                Duration timeout)
        Create a new instance of StatefulRedisConnectionImpl or a subclass.

        Subclasses of RedisClient may override that method.

        Type Parameters:
        K - Key-Type
        V - Value Type
        Parameters:
        channelWriter - the channel writer
        pushHandler - the handler for push notifications
        codec - codec
        timeout - default timeout
        Returns:
        new instance of StatefulRedisConnectionImpl