org.redisson.client.protocol.CommandsData Java Examples
The following examples show how to use
org.redisson.client.protocol.CommandsData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisConnectionInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodEnter private static void beforeSend(@Advice.This RedisConnection connection, @Advice.Argument(0) Object args, @Nullable @Advice.Local("span") Span span) { span = RedisSpanUtils.createRedisSpan(""); if (span != null) { // get command if (args instanceof CommandsData) { List<CommandData<?, ?>> commands = ((CommandsData) args).getCommands(); if (commands != null && !commands.isEmpty()) { span.appendToName(commands.get(0).getCommand().getName()).appendToName("... [bulk]"); } } else if (args instanceof CommandData) { span.appendToName(((CommandData) args).getCommand().getName()); } // get connection address Channel channel = connection.getChannel(); InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress(); span.getContext().getDestination() .withAddress(remoteAddress.getAddress().getHostAddress()) .withPort(remoteAddress.getPort()); } }
Example #2
Source File: RedisClientTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPipeline() throws InterruptedException, ExecutionException { RedisConnection conn = redisClient.connect(); conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0); List<CommandData<?, ?>> commands = new ArrayList<CommandData<?, ?>>(); CommandData<String, String> cmd1 = conn.create(null, RedisCommands.PING); commands.add(cmd1); CommandData<Long, Long> cmd2 = conn.create(null, RedisCommands.INCR, "test"); commands.add(cmd2); CommandData<Long, Long> cmd3 = conn.create(null, RedisCommands.INCR, "test"); commands.add(cmd3); CommandData<String, String> cmd4 = conn.create(null, RedisCommands.PING); commands.add(cmd4); RPromise<Void> p = new RedissonPromise<Void>(); conn.send(new CommandsData(p, commands, false, false)); assertThat(cmd1.getPromise().get()).isEqualTo("PONG"); assertThat(cmd2.getPromise().get()).isEqualTo(1); assertThat(cmd3.getPromise().get()).isEqualTo(2); assertThat(cmd4.getPromise().get()).isEqualTo("PONG"); conn.sync(RedisCommands.FLUSHDB); }
Example #3
Source File: RedisClientTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPipelineBigResponse() throws InterruptedException, ExecutionException { RedisConnection conn = redisClient.connect(); List<CommandData<?, ?>> commands = new ArrayList<CommandData<?, ?>>(); for (int i = 0; i < 1000; i++) { CommandData<String, String> cmd1 = conn.create(null, RedisCommands.PING); commands.add(cmd1); } RPromise<Void> p = new RedissonPromise<Void>(); conn.send(new CommandsData(p, commands, false, false)); for (CommandData<?, ?> commandData : commands) { commandData.getPromise().get(); } conn.sync(RedisCommands.FLUSHDB); }
Example #4
Source File: CommandBatchEncoder.java From redisson with Apache License 2.0 | 5 votes |
@Override protected void encode(ChannelHandlerContext ctx, CommandsData msg, ByteBuf out) throws Exception { CommandEncoder encoder = ctx.pipeline().get(CommandEncoder.class); for (CommandData<?, ?> commandData : msg.getCommands()) { encoder.encode(ctx, commandData, out); } }
Example #5
Source File: RedisCommonBatchExecutor.java From redisson with Apache License 2.0 | 5 votes |
@Override protected void sendCommand(RPromise<Void> attemptPromise, RedisConnection connection) { boolean isAtomic = options.getExecutionMode() != ExecutionMode.IN_MEMORY; boolean isQueued = options.getExecutionMode() == ExecutionMode.REDIS_READ_ATOMIC || options.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC; List<CommandData<?, ?>> list = new ArrayList<>(entry.getCommands().size()); if (source.getRedirect() == Redirect.ASK) { RPromise<Void> promise = new RedissonPromise<Void>(); list.add(new CommandData<Void, Void>(promise, StringCodec.INSTANCE, RedisCommands.ASKING, new Object[] {})); } for (CommandData<?, ?> c : entry.getCommands()) { if ((c.getPromise().isCancelled() || c.getPromise().isSuccess()) && !isWaitCommand(c) && !isAtomic) { // skip command continue; } list.add(c); } if (list.isEmpty()) { writeFuture = connection.getChannel().newPromise(); attemptPromise.trySuccess(null); timeout.cancel(); return; } writeFuture = connection.send(new CommandsData(attemptPromise, list, options.isSkipResult(), isAtomic, isQueued, options.getSyncSlaves() > 0)); }
Example #6
Source File: RedisConnection.java From redisson with Apache License 2.0 | 4 votes |
public ChannelFuture send(CommandsData data) { return channel.writeAndFlush(data); }