@Override public Flux<NumericResponse<Collection<ByteBuffer>, Long>> touch(Publisher<Collection<ByteBuffer>> keysCollection) { return connection.execute(cmd -> Flux.from(keysCollection).concatMap((keys) -> { Assert.notEmpty(keys, "Keys must not be null!"); return cmd.touch(keys.toArray(new ByteBuffer[keys.size()])).map((value) -> new NumericResponse<>(keys, value)); })); }
@Override public Flux<MultiValueResponse<ByteBuffer, ByteBuffer>> keys(Publisher<ByteBuffer> patterns) { return connection.execute(cmd -> Flux.from(patterns).concatMap(pattern -> { Assert.notNull(pattern, "Pattern must not be null!"); // TODO: stream elements instead of collection return cmd.keys(pattern).collectList().map(value -> new MultiValueResponse<>(pattern, value)); })); }
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); long timeout = command.getTimeout().get(ChronoUnit.SECONDS); Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection()) ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)) : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))) .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new); return mappedMono.map(value -> new PopResponse(command, value)); })); }
@Nullable Map<String, Object> hints) { Assert.notNull(inputStream, "'inputStream' must not be null"); Assert.notNull(bufferFactory, "'bufferFactory' must not be null"); Assert.notNull(elementType, "'elementType' must not be null"); (mimeType != null ? getAsciiBytes("Content-Type: " + mimeType + "\r\n") : new byte[0]); return Flux.from(inputStream). concatMap(region -> { if (!region.getResource().isReadable()) { return Flux.error(new EncodingException("Resource " +
@Override public Flux<MultiValueResponse<List<ByteBuffer>, ByteBuffer>> mGet(Publisher<List<ByteBuffer>> keyCollections) { return connection.execute(cmd -> Flux.from(keyCollections).concatMap((keys) -> { Assert.notNull(keys, "Keys must not be null!"); return cmd.mget(keys.toArray(new ByteBuffer[0])).map((value) -> value.getValueOrElse(EMPTY_BYTE_BUFFER)) .collectList().map((values) -> new MultiValueResponse<>(keys, values)); })); }
@Override public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getDestination(), "Destination key must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination()) .map(value -> new ByteBufferResponse<>(command, value)); })); }
@Override public final Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { return Flux.from(inputStream). take(1). concatMap(t -> encode(t, bufferFactory, elementType, mimeType, hints)); }
@Override public Flux<CommandResponse<SInterCommand, Flux<ByteBuffer>>> sInter(Publisher<SInterCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Flux<ByteBuffer> result = cmd.sinter(command.getKeys().toArray(new ByteBuffer[0])); return Mono.just(new CommandResponse<>(command, result)); })); }
@Override public Flux<BooleanResponse<MSetCommand>> mSetNX(Publisher<MSetCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notEmpty(command.getKeyValuePairs(), "Pairs must not be null or empty!"); return cmd.msetnx(command.getKeyValuePairs()).map((value) -> new BooleanResponse<>(command, value)); })); }
@Override public Flux<CommandResponse<KeyCommand, Flux<Map.Entry<ByteBuffer, ByteBuffer>>>> hGetAll( Publisher<KeyCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Mono<Map<ByteBuffer, ByteBuffer>> result = cmd.hgetall(command.getKey()); return Mono.just(new CommandResponse<>(command, result.flatMapMany(v -> Flux.fromStream(v.entrySet().stream())))); })); }
@Override public Flux<ReactiveRedisConnection.BooleanResponse<MSetCommand>> mSetNX(Publisher<MSetCommand> commands) { return getConnection().execute(cmd -> Flux.from(commands).concatMap(command -> { if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKeyValuePairs().keySet())) { return super.mSetNX(Mono.just(command)); } return Mono .error(new InvalidDataAccessApiUsageException("All keys must map to the same slot for MSETNX command.")); })); } }
@Override public Flux<CommandResponse<SDiffCommand, Flux<ByteBuffer>>> sDiff(Publisher<SDiffCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Flux<ByteBuffer> result = cmd.sdiff(command.getKeys().toArray(new ByteBuffer[0])); return Mono.just(new CommandResponse<>(command, result)); })); }
@Override public Flux<ReactiveRedisConnection.NumericResponse<BitOpCommand, Long>> bitOp(Publisher<BitOpCommand> commands) { return getConnection().execute(cmd -> Flux.from(commands).concatMap(command -> { List<ByteBuffer> keys = new ArrayList<>(command.getKeys()); keys.add(command.getDestinationKey()); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.bitOp(Mono.just(command)); } return Mono .error(new InvalidDataAccessApiUsageException("All keys must map to the same slot for BITOP command.")); })); }
@Override public final Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { return Flux.from(inputStream). take(1). concatMap(t -> encode(t, bufferFactory, elementType, mimeType, hints)); }
@Override public Flux<CommandResponse<KeyCommand, DataType>> type(Publisher<KeyCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); return cmd.type(command.getKey()).map(LettuceConverters::toDataType) .map(respValue -> new CommandResponse<>(command, respValue)); })); }
@Override public Flux<NumericResponse<ZUnionStoreCommand, Long>> zUnionStore(Publisher<ZUnionStoreCommand> commands) { return getConnection().execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notEmpty(command.getSourceKeys(), "Source keys must not be null or empty."); if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getSourceKeys())) { return super.zUnionStore(Mono.just(command)); } return Mono .error(new InvalidDataAccessApiUsageException("All keys must map to the same slot for ZUNIONSTORE command.")); })); }