use of io.lettuce.core.output.CommandOutput in project ballcat by ballcat-projects.
the class AbstractRedisModuleHelper method execute.
@SuppressWarnings("unchecked")
protected <T> Optional<T> execute(String key, ProtocolKeyword type, CommandOutput<byte[], byte[], T> output, String... args) {
List<byte[]> extraArgs = Arrays.stream(args).filter(StringUtils::hasLength).map(arg -> valueSerializer.serialize(arg)).collect(Collectors.toList());
CommandArgs<byte[], byte[]> commandArgs = new CommandArgs<>(codec).addKey(keySerializer.serialize(key)).addValues(extraArgs);
try (LettuceConnection connection = (LettuceConnection) connectionFactory.getConnection()) {
RedisFuture<T> future = connection.getNativeConnection().dispatch(type, output, commandArgs);
return Optional.ofNullable(future.get());
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error("[execute] 执行异常, KEY: [{}], type: [{}], args: [{}]", key, type.name(), args, e);
}
return Optional.empty();
}
Aggregations