Search in sources :

Example 6 with CommandExpiryWriter

use of io.lettuce.core.protocol.CommandExpiryWriter in project lettuce-core by lettuce-io.

the class ClusterDistributionChannelWriterUnitTests method shouldDisconnectWrappedEndpoint.

@Test
void shouldDisconnectWrappedEndpoint() {
    CommandListenerWriter listenerWriter = new CommandListenerWriter(defaultWriter, Collections.emptyList());
    CommandExpiryWriter expiryWriter = new CommandExpiryWriter(listenerWriter, ClientOptions.builder().timeoutOptions(TimeoutOptions.enabled()).build(), clientResources);
    ClusterDistributionChannelWriter writer = new ClusterDistributionChannelWriter(expiryWriter, ClientOptions.create(), clusterEventListener);
    writer.disconnectDefaultEndpoint();
    verify(defaultWriter).disconnect();
}
Also used : CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) CommandListenerWriter(io.lettuce.core.CommandListenerWriter) Test(org.junit.jupiter.api.Test)

Example 7 with CommandExpiryWriter

use of io.lettuce.core.protocol.CommandExpiryWriter in project lettuce-core by lettuce-io.

the class RedisClient method connectStandaloneAsync.

private <K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectStandaloneAsync(RedisCodec<K, V> codec, RedisURI redisURI, Duration timeout) {
    assertNotNull(codec);
    checkValidRedisURI(redisURI);
    logger.debug("Trying to get a Redis connection for: {}", redisURI);
    DefaultEndpoint endpoint = new DefaultEndpoint(getOptions(), getResources());
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getOptions())) {
        writer = new CommandExpiryWriter(writer, getOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    StatefulRedisConnectionImpl<K, V> connection = newStatefulRedisConnection(writer, endpoint, codec, timeout);
    ConnectionFuture<StatefulRedisConnection<K, V>> future = connectStatefulAsync(connection, endpoint, redisURI, () -> new CommandHandler(getOptions(), getResources(), endpoint));
    future.whenComplete((channelHandler, throwable) -> {
        if (throwable != null) {
            connection.closeAsync();
        }
    });
    return future;
}
Also used : CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Example 8 with CommandExpiryWriter

use of io.lettuce.core.protocol.CommandExpiryWriter in project lettuce-core by lettuce-io.

the class RedisClusterClient method connectToNodeAsync.

/**
 * Create a connection to a redis socket address.
 *
 * @param codec Use this codec to encode/decode keys and values, must not be {@code null}
 * @param nodeId the nodeId
 * @param clusterWriter global cluster writer
 * @param socketAddressSupplier supplier for the socket address
 * @param <K> Key type
 * @param <V> Value type
 * @return A new connection
 */
<K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectToNodeAsync(RedisCodec<K, V> codec, String nodeId, RedisChannelWriter clusterWriter, Mono<SocketAddress> socketAddressSupplier) {
    assertNotNull(codec);
    assertNotEmpty(initialUris);
    LettuceAssert.notNull(socketAddressSupplier, "SocketAddressSupplier must not be null");
    ClusterNodeEndpoint endpoint = new ClusterNodeEndpoint(getClusterClientOptions(), getResources(), clusterWriter);
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getClusterClientOptions())) {
        writer = new CommandExpiryWriter(writer, getClusterClientOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    StatefulRedisConnectionImpl<K, V> connection = newStatefulRedisConnection(writer, endpoint, codec, getFirstUri().getTimeout());
    ConnectionFuture<StatefulRedisConnection<K, V>> connectionFuture = connectStatefulAsync(connection, endpoint, getFirstUri(), socketAddressSupplier, () -> new CommandHandler(getClusterClientOptions(), getResources(), endpoint));
    return connectionFuture.whenComplete((conn, throwable) -> {
        if (throwable != null) {
            connection.closeAsync();
        }
    });
}
Also used : CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Aggregations

CommandExpiryWriter (io.lettuce.core.protocol.CommandExpiryWriter)8 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)5 CommandHandler (io.lettuce.core.protocol.CommandHandler)5 PubSubCommandHandler (io.lettuce.core.pubsub.PubSubCommandHandler)5 PubSubEndpoint (io.lettuce.core.pubsub.PubSubEndpoint)5 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)5 DefaultEndpoint (io.lettuce.core.protocol.DefaultEndpoint)4 StatefulRedisPubSubConnectionImpl (io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl)4 RedisCodec (io.lettuce.core.codec.RedisCodec)3 StringCodec (io.lettuce.core.codec.StringCodec)3 Futures (io.lettuce.core.internal.Futures)3 LettuceAssert (io.lettuce.core.internal.LettuceAssert)3 PushHandler (io.lettuce.core.protocol.PushHandler)3 ClientResources (io.lettuce.core.resource.ClientResources)3 InternalLogger (io.netty.util.internal.logging.InternalLogger)3 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)3 SocketAddress (java.net.SocketAddress)3 Duration (java.time.Duration)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3