Search in sources :

Example 1 with ByteArrayCodec

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

the class CommandSegmentCommandFactoryUnitTests method clientSetname.

@Test
void clientSetname() {
    RedisCommand<?, ?, ?> command = createCommand(methodOf(Commands.class, "clientSetname", String.class), new ByteArrayCodec(), "name");
    assertThat(toString(command)).isEqualTo("CLIENT SETNAME name");
}
Also used : ByteArrayCodec(io.lettuce.core.codec.ByteArrayCodec) Test(org.junit.jupiter.api.Test)

Example 2 with ByteArrayCodec

use of io.lettuce.core.codec.ByteArrayCodec in project pulsar by apache.

the class RedisSession method create.

public static RedisSession create(RedisSinkConfig config) {
    RedisSession redisSession;
    final RedisCodec<byte[], byte[]> codec = new ByteArrayCodec();
    final SocketOptions socketOptions = SocketOptions.builder().tcpNoDelay(config.isTcpNoDelay()).connectTimeout(Duration.ofMillis(config.getConnectTimeout())).keepAlive(config.isKeepAlive()).build();
    final ClientMode clientMode;
    try {
        clientMode = ClientMode.valueOf(config.getClientMode().toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Illegal Redis client mode, valid values are: " + Arrays.asList(ClientMode.values()));
    }
    List<RedisURI> redisURIs = redisURIs(config.getHostAndPorts(), config);
    if (clientMode == ClientMode.STANDALONE) {
        ClientOptions.Builder clientOptions = ClientOptions.builder().socketOptions(socketOptions).requestQueueSize(config.getRequestQueue()).autoReconnect(config.isAutoReconnect());
        final RedisClient client = RedisClient.create(redisURIs.get(0));
        client.setOptions(clientOptions.build());
        final StatefulRedisConnection<byte[], byte[]> connection = client.connect(codec);
        redisSession = new RedisSession(client, connection, connection.async());
    } else if (clientMode == ClientMode.CLUSTER) {
        ClusterClientOptions.Builder clientOptions = ClusterClientOptions.builder().requestQueueSize(config.getRequestQueue()).autoReconnect(config.isAutoReconnect());
        final RedisClusterClient client = RedisClusterClient.create(redisURIs);
        client.setOptions(clientOptions.build());
        final StatefulRedisClusterConnection<byte[], byte[]> connection = client.connect(codec);
        redisSession = new RedisSession(client, connection, connection.async());
    } else {
        throw new UnsupportedOperationException(String.format("%s is not supported", config.getClientMode()));
    }
    return redisSession;
}
Also used : ClientOptions(io.lettuce.core.ClientOptions) ClusterClientOptions(io.lettuce.core.cluster.ClusterClientOptions) RedisURI(io.lettuce.core.RedisURI) SocketOptions(io.lettuce.core.SocketOptions) ClientMode(org.apache.pulsar.io.redis.RedisAbstractConfig.ClientMode) ByteArrayCodec(io.lettuce.core.codec.ByteArrayCodec) RedisClient(io.lettuce.core.RedisClient) AbstractRedisClient(io.lettuce.core.AbstractRedisClient) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient)

Example 3 with ByteArrayCodec

use of io.lettuce.core.codec.ByteArrayCodec in project austin by ZhongFuCheng3y.

the class LettuceRedisUtils method pipeline.

/**
 * 封装pipeline操作
 */
public static void pipeline(RedisPipelineCallBack pipelineCallBack) {
    StatefulRedisConnection<byte[], byte[]> connect = redisClient.connect(new ByteArrayCodec());
    RedisAsyncCommands<byte[], byte[]> commands = connect.async();
    List<RedisFuture<?>> futures = pipelineCallBack.invoke(commands);
    commands.flushCommands();
    LettuceFutures.awaitAll(10, TimeUnit.SECONDS, futures.toArray(new RedisFuture[futures.size()]));
    connect.close();
}
Also used : ByteArrayCodec(io.lettuce.core.codec.ByteArrayCodec) RedisFuture(io.lettuce.core.RedisFuture)

Example 4 with ByteArrayCodec

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

the class ByteCodecClusterIntegrationTests method testByteCodec.

@Test
@Inject
void testByteCodec(RedisClusterClient clusterClient) {
    StatefulRedisClusterConnection<byte[], byte[]> connection = clusterClient.connect(new ByteArrayCodec());
    connection.sync().set(key.getBytes(), value.getBytes());
    assertThat(connection.sync().get(key.getBytes())).isEqualTo(value.getBytes());
}
Also used : ByteArrayCodec(io.lettuce.core.codec.ByteArrayCodec) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test)

Example 5 with ByteArrayCodec

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

the class CommandSegmentCommandFactoryUnitTests method setKeyValueWithByteArrayCodec.

@Test
void setKeyValueWithByteArrayCodec() {
    RedisCommand<?, ?, ?> command = createCommand(methodOf(Commands.class, "set", String.class, String.class), new ByteArrayCodec(), "key", "value");
    assertThat(toString(command)).isEqualTo("SET key value");
}
Also used : ByteArrayCodec(io.lettuce.core.codec.ByteArrayCodec) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayCodec (io.lettuce.core.codec.ByteArrayCodec)5 Test (org.junit.jupiter.api.Test)3 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)1 ClientOptions (io.lettuce.core.ClientOptions)1 RedisClient (io.lettuce.core.RedisClient)1 RedisFuture (io.lettuce.core.RedisFuture)1 RedisURI (io.lettuce.core.RedisURI)1 SocketOptions (io.lettuce.core.SocketOptions)1 ClusterClientOptions (io.lettuce.core.cluster.ClusterClientOptions)1 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)1 StatefulRedisClusterConnection (io.lettuce.core.cluster.api.StatefulRedisClusterConnection)1 Inject (javax.inject.Inject)1 ClientMode (org.apache.pulsar.io.redis.RedisAbstractConfig.ClientMode)1