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");
}
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;
}
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();
}
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());
}
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");
}
Aggregations