public <T, R> CommandData<T, R> create(Codec encoder, RedisCommand<T> command, Object ... params) { RPromise<R> promise = new RedissonPromise<R>(); return new CommandData<T, R>(promise, encoder, command, params); }
protected void completeResponse(CommandData<Object, Object> data, Object result, Channel channel) { if (data != null && !data.getPromise().trySuccess(result) && data.cause() instanceof RedisTimeoutException) { log.warn("response has been skipped due to timeout! channel: {}, command: {}, result: {}", channel, LogHelper.toString(data), LogHelper.toString(result)); } }
MultiDecoder<Object> multiDecoder = data.getCommand().getReplayMultiDecoder(); if (multiDecoder != null) { Decoder<Object> mDecoder = multiDecoder.getDecoder(parts.size(), state()); Decoder<Object> decoder = data.getCommand().getReplayDecoder(); if (decoder == null) { if (data.getCodec() == null) { return StringCodec.INSTANCE.getValueDecoder(); if (data.getCommand().getOutParamType() == ValueType.MAP) { if (parts != null && parts.size() % 2 != 0) { return data.getCodec().getMapValueDecoder(); } else { return data.getCodec().getMapKeyDecoder(); } else if (data.getCommand().getOutParamType() == ValueType.MAP_KEY) { return data.getCodec().getMapKeyDecoder(); } else if (data.getCommand().getOutParamType() == ValueType.MAP_VALUE) { return data.getCodec().getMapValueDecoder(); } else { return data.getCodec().getValueDecoder();
private void reattachBlockingQueue(RedisConnection connection, CommandData<?, ?> currentCommand) { if (currentCommand == null || !currentCommand.isBlockingCommand() || currentCommand.getPromise().isDone()) { return; } log.debug("blocking queue sent " + connection); ChannelFuture future = connection.send(currentCommand); final CommandData<?, ?> cd = currentCommand; future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { log.error("Can't reconnect blocking queue to new connection. {}", cd); } } }); }
} else if (object instanceof CommandData) { CommandData<?, ?> cd = (CommandData<?, ?>)object; if (RedisCommands.AUTH.equals(cd.getCommand())) { return cd.getCommand() + ", params: (password masked)"; return cd.getCommand() + ", params: " + LogHelper.toString(cd.getParams()); } else if (object instanceof ByteBuf) { final ByteBuf byteBuf = (ByteBuf) object;
for (int i = respParts.size(); i < size; i++) { int suffix = 0; if (RedisCommands.MULTI.getName().equals(commands.get(0).getCommand().getName())) { suffix = 1; if (commandData.getPromise().isDone() && !commandData.getPromise().isSuccess()) { data.tryFailure(commandData.cause());
try { out.writeByte(ARGS_PREFIX); int len = 1 + msg.getParams().length; if (msg.getCommand().getSubName() != null) { len++; out.writeBytes(CRLF); writeArgument(out, msg.getCommand().getName().getBytes(CharsetUtil.UTF_8)); if (msg.getCommand().getSubName() != null) { writeArgument(out, msg.getCommand().getSubName().getBytes(CharsetUtil.UTF_8)); for (Object param : msg.getParams()) { ByteBuf buf = encode(param); writeArgument(out, buf); if (RedisCommands.AUTH.equals(msg.getCommand())) { info = info.substring(0, info.indexOf(RedisCommands.AUTH.getName()) + RedisCommands.AUTH.getName().length()) + "(password masked)"; msg.tryFailure(e); throw e;
|| !commandData.isBlockingCommand() || commandData.getPromise().isDone()) { return; RFuture<RedisConnection> newConnection = connectionWriteOp(commandData.getCommand()); newConnection.addListener(new FutureListener<RedisConnection>() { @Override
@Override public List<CommandData<Object, Object>> getPubSubOperations() { List<CommandData<Object, Object>> result = new ArrayList<CommandData<Object, Object>>(); for (CommandData<?, ?> commandData : commands) { if (RedisCommands.PUBSUB_COMMANDS.equals(commandData.getCommand().getName())) { result.add((CommandData<Object, Object>)commandData); } } return result; }
@Override public boolean tryFailure(Throwable cause) { if (redirectError.get() != null) { return false; } if (cause instanceof RedisRedirectException) { return redirectError.compareAndSet(null, (RedisRedirectException) cause); } return super.tryFailure(cause); }
PubSubKey key = new PubSubKey(channelName, operation); CommandData<Object, Object> d = commands.get(key); if (Arrays.asList(RedisCommands.PSUBSCRIBE.getName(), RedisCommands.SUBSCRIBE.getName()).contains(d.getCommand().getName())) { commands.remove(key); entries.put(channelName, new PubSubEntry(d.getMessageDecoder())); if (Arrays.asList(RedisCommands.PUNSUBSCRIBE.getName(), RedisCommands.UNSUBSCRIBE.getName()).contains(d.getCommand().getName())) { commands.remove(key); if (result instanceof PubSubPatternMessage) { if (data != null && data.getCommand().getName().equals("PING")) { super.decodeResult(data, parts, ctx, result);
@Override public void run(Timeout timeout) throws Exception { CommandData<?, ?> commandData = connection.getCurrentCommand(); if ((commandData == null || !commandData.isBlockingCommand()) && (future.cancel(false) || !future.isSuccess())) { ctx.channel().close(); log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval()); } else { sendPing(ctx); } } }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS);
@Override public Throwable cause() { if (redirectError.get() != null) { return redirectError.get(); } return super.cause(); }
@Override public boolean isSuccess() { return redirectError.get() == null && super.isSuccess(); }
private void sendData(Channel ch) { QueueCommandHolder command = queue.peek(); if (command != null && command.trySend()) { QueueCommand data = command.getCommand(); List<CommandData<Object, Object>> pubSubOps = data.getPubSubOperations(); if (!pubSubOps.isEmpty()) { for (CommandData<Object, Object> cd : pubSubOps) { for (Object channel : cd.getParams()) { ch.pipeline().get(CommandPubSubDecoder.class).addPubSubCommand((ChannelName) channel, cd); } } } else { ch.attr(CURRENT_COMMAND).set(data); } command.getChannelPromise().addListener(listener); ch.writeAndFlush(data, command.getChannelPromise()); } }
commandData.getPromise().addListener(listener); if (commandData.getPromise().isDone()) { return;
for (int i = respParts.size(); i < size; i++) { int suffix = 0; if (RedisCommands.MULTI.getName().equals(commands.get(0).getCommand().getName())) { suffix = 1; if (commandData.getPromise().isDone() && !commandData.getPromise().isSuccess()) { data.tryFailure(commandData.cause());
try { out.writeByte(ARGS_PREFIX); int len = 1 + msg.getParams().length; if (msg.getCommand().getSubName() != null) { len++; out.writeBytes(CRLF); writeArgument(out, msg.getCommand().getName().getBytes(CharsetUtil.UTF_8)); if (msg.getCommand().getSubName() != null) { writeArgument(out, msg.getCommand().getSubName().getBytes(CharsetUtil.UTF_8)); for (Object param : msg.getParams()) { ByteBuf buf = encode(param); writeArgument(out, buf); if (RedisCommands.AUTH.equals(msg.getCommand())) { info = info.substring(0, info.indexOf(RedisCommands.AUTH.getName()) + RedisCommands.AUTH.getName().length()) + "(password masked)"; msg.tryFailure(e); throw e;
|| !commandData.isBlockingCommand() || commandData.getPromise().isDone()) { return; RFuture<RedisConnection> newConnection = connectionWriteOp(commandData.getCommand()); newConnection.addListener(new FutureListener<RedisConnection>() { @Override
@Override public List<CommandData<Object, Object>> getPubSubOperations() { if (RedisCommands.PUBSUB_COMMANDS.contains(getCommand().getName())) { return Collections.singletonList((CommandData<Object, Object>)this); } return Collections.emptyList(); }