Search in sources :

Example 1 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project lettuce-core by lettuce-io.

the class RedisClient method doConnectSentinelAsync.

private <K, V> ConnectionFuture<StatefulRedisSentinelConnection<K, V>> doConnectSentinelAsync(RedisCodec<K, V> codec, RedisURI redisURI, Duration timeout, String clientName) {
    ConnectionBuilder connectionBuilder;
    if (redisURI.isSsl()) {
        SslConnectionBuilder sslConnectionBuilder = SslConnectionBuilder.sslConnectionBuilder();
        sslConnectionBuilder.ssl(redisURI);
        connectionBuilder = sslConnectionBuilder;
    } else {
        connectionBuilder = ConnectionBuilder.connectionBuilder();
    }
    connectionBuilder.clientOptions(ClientOptions.copyOf(getOptions()));
    connectionBuilder.clientResources(getResources());
    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());
    }
    StatefulRedisSentinelConnectionImpl<K, V> connection = newStatefulRedisSentinelConnection(writer, codec, timeout);
    ConnectionState state = connection.getConnectionState();
    state.apply(redisURI);
    if (LettuceStrings.isEmpty(state.getClientName())) {
        state.setClientName(clientName);
    }
    connectionBuilder.connectionInitializer(createHandshake(state));
    logger.debug("Connecting to Redis Sentinel, address: " + redisURI);
    connectionBuilder.endpoint(endpoint).commandHandler(() -> new CommandHandler(getOptions(), getResources(), endpoint)).connection(connection);
    connectionBuilder(getSocketAddressSupplier(redisURI), connectionBuilder, connection.getConnectionEvents(), redisURI);
    ConnectionFuture<?> sync = initializeChannelAsync(connectionBuilder);
    return sync.thenApply(ignore -> (StatefulRedisSentinelConnection<K, V>) connection).whenComplete((ignore, e) -> {
        if (e != null) {
            logger.warn("Cannot connect Redis Sentinel at " + redisURI + ": " + e);
            connection.closeAsync();
        }
    });
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) SocketAddress(java.net.SocketAddress) StringCodec(io.lettuce.core.codec.StringCodec) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) PushHandler(io.lettuce.core.protocol.PushHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) Futures(io.lettuce.core.internal.Futures) LettuceAssert(io.lettuce.core.internal.LettuceAssert) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Duration(java.time.Duration) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) StatefulRedisSentinelConnectionImpl(io.lettuce.core.sentinel.StatefulRedisSentinelConnectionImpl) ExceptionFactory(io.lettuce.core.internal.ExceptionFactory) CommandHandler(io.lettuce.core.protocol.CommandHandler) Endpoint(io.lettuce.core.protocol.Endpoint) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) CompletionException(java.util.concurrent.CompletionException) Mono(reactor.core.publisher.Mono) InetSocketAddress(java.net.InetSocketAddress) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MasterReplica(io.lettuce.core.masterreplica.MasterReplica) RedisCodec(io.lettuce.core.codec.RedisCodec) StatefulRedisSentinelConnection(io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection) StatefulRedisPubSubConnectionImpl(io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) LettuceStrings(io.lettuce.core.internal.LettuceStrings) InternalLogger(io.netty.util.internal.logging.InternalLogger) Queue(java.util.Queue) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisSentinelConnection(io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection)

Example 2 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project lettuce-core by lettuce-io.

the class OutputRegistry method getOutputComponentType.

/**
 * Retrieve {@link OutputType} for a {@link CommandOutput} type.
 *
 * @param commandOutputClass
 * @return
 */
static OutputType getOutputComponentType(Class<? extends CommandOutput> commandOutputClass) {
    ClassTypeInformation<? extends CommandOutput> classTypeInformation = ClassTypeInformation.from(commandOutputClass);
    TypeInformation<?> superTypeInformation = classTypeInformation.getSuperTypeInformation(CommandOutput.class);
    if (superTypeInformation == null) {
        return null;
    }
    List<TypeInformation<?>> typeArguments = superTypeInformation.getTypeArguments();
    return new OutputType(commandOutputClass, typeArguments.get(2), false) {

        @Override
        public ResolvableType withCodec(RedisCodec<?, ?> codec) {
            TypeInformation<?> typeInformation = ClassTypeInformation.from(codec.getClass());
            ResolvableType resolvableType = ResolvableType.forType(commandOutputClass, new CodecVariableTypeResolver(typeInformation));
            while (!resolvableType.getRawClass().equals(CommandOutput.class)) {
                resolvableType = resolvableType.getSuperType();
            }
            return resolvableType.getGeneric(2);
        }
    };
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) ResolvableType(io.lettuce.core.dynamic.support.ResolvableType) ClassTypeInformation(io.lettuce.core.dynamic.support.ClassTypeInformation) TypeInformation(io.lettuce.core.dynamic.support.TypeInformation)

Example 3 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project lettuce-core by lettuce-io.

the class RedisClusterClient method connectClusterAsync.

/**
 * Create a clustered pub/sub connection with command distributor.
 *
 * @param codec Use this codec to encode/decode keys and values, must not be {@code null}
 * @param <K> Key type
 * @param <V> Value type
 * @return a new connection
 */
private <K, V> CompletableFuture<StatefulRedisClusterConnection<K, V>> connectClusterAsync(RedisCodec<K, V> codec) {
    if (partitions == null) {
        return Futures.failed(new IllegalStateException("Partitions not initialized. Initialize via RedisClusterClient.getPartitions()."));
    }
    topologyRefreshScheduler.activateTopologyRefreshIfNeeded();
    logger.debug("connectCluster(" + initialUris + ")");
    DefaultEndpoint endpoint = new DefaultEndpoint(getClusterClientOptions(), getResources());
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getClusterClientOptions())) {
        writer = new CommandExpiryWriter(writer, getClusterClientOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    ClusterDistributionChannelWriter clusterWriter = new ClusterDistributionChannelWriter(writer, getClusterClientOptions(), topologyRefreshScheduler);
    PooledClusterConnectionProvider<K, V> pooledClusterConnectionProvider = new PooledClusterConnectionProvider<>(this, clusterWriter, codec, topologyRefreshScheduler);
    clusterWriter.setClusterConnectionProvider(pooledClusterConnectionProvider);
    StatefulRedisClusterConnectionImpl<K, V> connection = newStatefulRedisClusterConnection(clusterWriter, pooledClusterConnectionProvider, codec, getFirstUri().getTimeout());
    connection.setReadFrom(ReadFrom.UPSTREAM);
    connection.setPartitions(partitions);
    Supplier<CommandHandler> commandHandlerSupplier = () -> new CommandHandler(getClusterClientOptions(), getResources(), endpoint);
    Mono<SocketAddress> socketAddressSupplier = getSocketAddressSupplier(connection::getPartitions, TopologyComparators::sortByClientCount);
    Mono<StatefulRedisClusterConnectionImpl<K, V>> connectionMono = Mono.defer(() -> connect(socketAddressSupplier, endpoint, connection, commandHandlerSupplier));
    for (int i = 1; i < getConnectionAttempts(); i++) {
        connectionMono = connectionMono.onErrorResume(t -> connect(socketAddressSupplier, endpoint, connection, commandHandlerSupplier));
    }
    return connectionMono.doOnNext(c -> connection.registerCloseables(closeableResources, clusterWriter, pooledClusterConnectionProvider)).map(it -> (StatefulRedisClusterConnection<K, V>) it).toFuture();
}
Also used : StatefulRedisClusterPubSubConnection(io.lettuce.core.cluster.pubsub.StatefulRedisClusterPubSubConnection) SocketAddress(java.net.SocketAddress) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) Futures(io.lettuce.core.internal.Futures) LettuceAssert(io.lettuce.core.internal.LettuceAssert) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Duration(java.time.Duration) Map(java.util.Map) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) URI(java.net.URI) CommandHandler(io.lettuce.core.protocol.CommandHandler) LettuceLists(io.lettuce.core.internal.LettuceLists) Exceptions(io.lettuce.core.internal.Exceptions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RedisCodec(io.lettuce.core.codec.RedisCodec) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) TopologyRefreshEvent(io.lettuce.core.cluster.event.TopologyRefreshEvent) StatefulRedisPubSubConnectionImpl(io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl) ClusterTopologyChangedEvent(io.lettuce.core.cluster.event.ClusterTopologyChangedEvent) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) InternalLogger(io.netty.util.internal.logging.InternalLogger) KeyValueStreamingChannel(io.lettuce.core.output.KeyValueStreamingChannel) io.lettuce.core(io.lettuce.core) NodeSelectionSupport(io.lettuce.core.cluster.api.NodeSelectionSupport) ClusterTopologyRefresh(io.lettuce.core.cluster.topology.ClusterTopologyRefresh) ClientResources(io.lettuce.core.resource.ClientResources) TopologyComparators(io.lettuce.core.cluster.topology.TopologyComparators) StringCodec(io.lettuce.core.codec.StringCodec) PushHandler(io.lettuce.core.protocol.PushHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RedisAdvancedClusterAsyncCommands(io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) NodeConnectionFactory(io.lettuce.core.cluster.topology.NodeConnectionFactory) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisAdvancedClusterCommands(io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) Mono(reactor.core.publisher.Mono) EventRecorder(io.lettuce.core.event.jfr.EventRecorder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Closeable(java.io.Closeable) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Collections(java.util.Collections) TopologyComparators(io.lettuce.core.cluster.topology.TopologyComparators) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) SocketAddress(java.net.SocketAddress)

Example 4 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project lettuce-core by lettuce-io.

the class RedisClusterClient method connectClusterPubSubAsync.

/**
 * Create a clustered connection with command distributor.
 *
 * @param codec Use this codec to encode/decode keys and values, must not be {@code null}
 * @param <K> Key type
 * @param <V> Value type
 * @return a new connection
 */
private <K, V> CompletableFuture<StatefulRedisClusterPubSubConnection<K, V>> connectClusterPubSubAsync(RedisCodec<K, V> codec) {
    if (partitions == null) {
        return Futures.failed(new IllegalStateException("Partitions not initialized. Initialize via RedisClusterClient.getPartitions()."));
    }
    topologyRefreshScheduler.activateTopologyRefreshIfNeeded();
    logger.debug("connectClusterPubSub(" + initialUris + ")");
    PubSubClusterEndpoint<K, V> endpoint = new PubSubClusterEndpoint<>(getClusterClientOptions(), getResources());
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getClusterClientOptions())) {
        writer = new CommandExpiryWriter(writer, getClusterClientOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    ClusterDistributionChannelWriter clusterWriter = new ClusterDistributionChannelWriter(writer, getClusterClientOptions(), topologyRefreshScheduler);
    ClusterPubSubConnectionProvider<K, V> pooledClusterConnectionProvider = new ClusterPubSubConnectionProvider<>(this, clusterWriter, codec, endpoint.getUpstreamListener(), topologyRefreshScheduler);
    StatefulRedisClusterPubSubConnectionImpl<K, V> connection = new StatefulRedisClusterPubSubConnectionImpl<>(endpoint, pooledClusterConnectionProvider, clusterWriter, codec, getFirstUri().getTimeout());
    clusterWriter.setClusterConnectionProvider(pooledClusterConnectionProvider);
    connection.setPartitions(partitions);
    Supplier<CommandHandler> commandHandlerSupplier = () -> new PubSubCommandHandler<>(getClusterClientOptions(), getResources(), codec, endpoint);
    Mono<SocketAddress> socketAddressSupplier = getSocketAddressSupplier(connection::getPartitions, TopologyComparators::sortByClientCount);
    Mono<StatefulRedisClusterPubSubConnectionImpl<K, V>> connectionMono = Mono.defer(() -> connect(socketAddressSupplier, endpoint, connection, commandHandlerSupplier));
    for (int i = 1; i < getConnectionAttempts(); i++) {
        connectionMono = connectionMono.onErrorResume(t -> connect(socketAddressSupplier, endpoint, connection, commandHandlerSupplier));
    }
    return connectionMono.doOnNext(c -> connection.registerCloseables(closeableResources, clusterWriter, pooledClusterConnectionProvider)).map(it -> (StatefulRedisClusterPubSubConnection<K, V>) it).toFuture();
}
Also used : StatefulRedisClusterPubSubConnection(io.lettuce.core.cluster.pubsub.StatefulRedisClusterPubSubConnection) SocketAddress(java.net.SocketAddress) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) Futures(io.lettuce.core.internal.Futures) LettuceAssert(io.lettuce.core.internal.LettuceAssert) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Duration(java.time.Duration) Map(java.util.Map) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) URI(java.net.URI) CommandHandler(io.lettuce.core.protocol.CommandHandler) LettuceLists(io.lettuce.core.internal.LettuceLists) Exceptions(io.lettuce.core.internal.Exceptions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RedisCodec(io.lettuce.core.codec.RedisCodec) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) TopologyRefreshEvent(io.lettuce.core.cluster.event.TopologyRefreshEvent) StatefulRedisPubSubConnectionImpl(io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl) ClusterTopologyChangedEvent(io.lettuce.core.cluster.event.ClusterTopologyChangedEvent) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) InternalLogger(io.netty.util.internal.logging.InternalLogger) KeyValueStreamingChannel(io.lettuce.core.output.KeyValueStreamingChannel) io.lettuce.core(io.lettuce.core) NodeSelectionSupport(io.lettuce.core.cluster.api.NodeSelectionSupport) ClusterTopologyRefresh(io.lettuce.core.cluster.topology.ClusterTopologyRefresh) ClientResources(io.lettuce.core.resource.ClientResources) TopologyComparators(io.lettuce.core.cluster.topology.TopologyComparators) StringCodec(io.lettuce.core.codec.StringCodec) PushHandler(io.lettuce.core.protocol.PushHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RedisAdvancedClusterAsyncCommands(io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) NodeConnectionFactory(io.lettuce.core.cluster.topology.NodeConnectionFactory) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisAdvancedClusterCommands(io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) Mono(reactor.core.publisher.Mono) EventRecorder(io.lettuce.core.event.jfr.EventRecorder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Closeable(java.io.Closeable) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Collections(java.util.Collections) TopologyComparators(io.lettuce.core.cluster.topology.TopologyComparators) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) StatefulRedisClusterPubSubConnection(io.lettuce.core.cluster.pubsub.StatefulRedisClusterPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) SocketAddress(java.net.SocketAddress)

Example 5 with RedisCodec

use of io.lettuce.core.codec.RedisCodec in project LinkAgent by shulieTech.

the class LettuceMasterSlaveFactory method createMediator.

@Override
public RedisClientMediator<Object> createMediator(Object obj, ShadowRedisConfig shadowRedisConfig) {
    if (!(obj instanceof Advice)) {
        return null;
    }
    boolean isSentinel = false;
    boolean withDataBase = shadowRedisConfig.getDatabase() != null;
    Integer pressureDatabase = shadowRedisConfig.getDatabase();
    Advice advice = (Advice) obj;
    RedisClientMediator<Object> mediator = null;
    try {
        String method = advice.getBehavior().getName();
        Object[] args = advice.getParameterArray();
        Object performanceConnection = null;
        List<RedisURI> performanceUris = new ArrayList<RedisURI>();
        RedisURI performanceUri = null;
        if (args[2] instanceof RedisURI) {
            isSentinel = isSentinel(args[2], shadowRedisConfig);
            String nodes = shadowRedisConfig.getNodes();
            if (isSentinel) {
                String[] nodesSplitter = nodes.split(",");
                RedisURI.Builder builder = RedisURI.builder();
                for (String node : nodesSplitter) {
                    String[] innerSplitter = node.split(":");
                    builder.withSentinel(innerSplitter[0], Integer.parseInt(innerSplitter[1]));
                    if (withDataBase) {
                        builder.withDatabase(pressureDatabase);
                    }
                }
                builder.withSentinelMasterId(shadowRedisConfig.getMaster());
                performanceUri = builder.build();
            } else {
                String[] nodesSplitter = nodes.split(",");
                for (String node : nodesSplitter) {
                    node = node.startsWith("redis://") ? node : "redis://" + node;
                    RedisURI uri = RedisURI.create(node);
                    if (withDataBase) {
                        uri.setDatabase(pressureDatabase);
                    }
                    performanceUris.add(uri);
                }
            }
        } else if (args[2] instanceof List) {
            isSentinel = isSentinel(args[2], shadowRedisConfig);
            String nodes = shadowRedisConfig.getNodes();
            if (isSentinel) {
                String[] nodesSplitter = nodes.split(",");
                RedisURI.Builder builder = RedisURI.builder();
                for (String node : nodesSplitter) {
                    builder.withSentinel(node);
                    if (withDataBase) {
                        builder.withDatabase(pressureDatabase);
                    }
                }
                builder.withSentinelMasterId(shadowRedisConfig.getMaster());
                performanceUri = builder.build();
            } else {
                String[] nodesSplitter = nodes.split(",");
                for (String node : nodesSplitter) {
                    node = node.startsWith("redis://") ? node : "redis://" + node;
                    RedisURI uri = RedisURI.create(node);
                    if (withDataBase) {
                        uri.setDatabase(pressureDatabase);
                    }
                    performanceUris.add(uri);
                }
                String shadowMaster = shadowRedisConfig.getMaster();
                if (!StringUtil.isEmpty(shadowMaster)) {
                    shadowMaster = shadowMaster.startsWith("redis://") ? shadowMaster : "redis://" + shadowMaster;
                    RedisURI uri = RedisURI.create(shadowMaster);
                    if (withDataBase) {
                        uri.setDatabase(pressureDatabase);
                    }
                    performanceUris.add(uri);
                }
            }
        } else {
        /* performanceUris.add(RedisURI.create(
                        shadowRedisConfig.getMaster().startsWith("redis://") ? shadowRedisConfig.getMaster() : "redis://" + shadowRedisConfig.getMaster())
                );
                for (String nodeNum : shadowRedisConfig.getNodeNums()) {
                    performanceUris.add(RedisURI.create("redis://" + nodeNum));
                }*/
        }
        LettuceUtils.cachePressureNode(performanceUri);
        LettuceUtils.cachePressureNode(performanceUris);
        if ("connect".equals(method)) {
            if (isRedisUri(args[2], performanceUri)) {
                performanceConnection = MasterSlave.connect((RedisClient) args[0], (RedisCodec) args[1], performanceUri);
            } else {
                performanceConnection = MasterSlave.connect((RedisClient) args[0], (RedisCodec) args[1], performanceUris);
            }
        } else if ("connectAsync".equals(method)) {
            if (isRedisUri(args[2], performanceUri)) {
                performanceConnection = MasterSlave.connectAsync((RedisClient) args[0], (RedisCodec) args[1], performanceUri);
            } else {
                performanceConnection = MasterSlave.connectAsync((RedisClient) args[0], (RedisCodec) args[1], performanceUris);
            }
        }
        mediator = new RedisClientMediator<Object>(advice.getReturnObj(), performanceConnection);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setErrorCode("redisServer-0001").setMessage("redis server lettuce master slave error!").setDetail(ExceptionUtils.getStackTrace(e)).report();
    }
    return mediator;
}
Also used : RedisURI(io.lettuce.core.RedisURI) RedisClient(io.lettuce.core.RedisClient) RedisCodec(io.lettuce.core.codec.RedisCodec) Advice(com.shulie.instrument.simulator.api.listener.ext.Advice)

Aggregations

RedisCodec (io.lettuce.core.codec.RedisCodec)6 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)3 StringCodec (io.lettuce.core.codec.StringCodec)3 Futures (io.lettuce.core.internal.Futures)3 LettuceAssert (io.lettuce.core.internal.LettuceAssert)3 CommandExpiryWriter (io.lettuce.core.protocol.CommandExpiryWriter)3 CommandHandler (io.lettuce.core.protocol.CommandHandler)3 DefaultEndpoint (io.lettuce.core.protocol.DefaultEndpoint)3 PushHandler (io.lettuce.core.protocol.PushHandler)3 PubSubCommandHandler (io.lettuce.core.pubsub.PubSubCommandHandler)3 PubSubEndpoint (io.lettuce.core.pubsub.PubSubEndpoint)3 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)3 StatefulRedisPubSubConnectionImpl (io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl)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