Refine search
@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<CommandResponse<RangeCommand, Flux<ByteBufferRecord>>> xRange(Publisher<RangeCommand> commands) { return connection.execute(cmd -> Flux.from(commands).map(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); Assert.notNull(command.getLimit(), "Limit must not be null!"); io.lettuce.core.Range<String> lettuceRange = RangeConverter.toRange(command.getRange(), Function.identity()); io.lettuce.core.Limit lettuceLimit = LettuceConverters.toLimit(command.getLimit()); return new CommandResponse<>(command, cmd.xrange(command.getKey(), lettuceRange, lettuceLimit) .map(it -> StreamRecords.newRecord().in(it.getStream()).withId(it.getId()).ofBuffer(it.getBody()))); })); }
@Override public Flux<CommandResponse<ReadCommand, Flux<ByteBufferRecord>>> read(Publisher<ReadCommand> commands) { return Flux.from(commands).map(command -> { Assert.notNull(command.getStreamOffsets(), "StreamOffsets must not be null!"); Assert.notNull(command.getReadOptions(), "ReadOptions must not be null!"); StreamReadOptions readOptions = command.getReadOptions(); if (readOptions.getBlock() != null && readOptions.getBlock() > 0) { return new CommandResponse<>(command, connection.executeDedicated(cmd -> doRead(command, readOptions, cmd))); } return new CommandResponse<>(command, connection.execute(cmd -> doRead(command, readOptions, cmd))); }); }
@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<CommandResponse<RangeCommand, Flux<ByteBufferRecord>>> xRevRange(Publisher<RangeCommand> commands) { return connection.execute(cmd -> Flux.from(commands).map(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getRange(), "Range must not be null!"); Assert.notNull(command.getLimit(), "Limit must not be null!"); io.lettuce.core.Range<String> lettuceRange = RangeConverter.toRange(command.getRange(), Function.identity()); io.lettuce.core.Limit lettuceLimit = LettuceConverters.toLimit(command.getLimit()); return new CommandResponse<>(command, cmd.xrevrange(command.getKey(), lettuceRange, lettuceLimit) .map(it -> StreamRecords.newRecord().in(it.getStream()).withId(it.getId()).ofBuffer(it.getBody()))); })); }
@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>> mSet(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.mset(command.getKeyValuePairs()).map(LettuceConverters::stringToBoolean) .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<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<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.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<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<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 Flux<CommandResponse<SUnionCommand, Flux<ByteBuffer>>> sUnion(Publisher<SUnionCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Flux<ByteBuffer> result = cmd.sunion(command.getKeys().toArray(new ByteBuffer[0])); return Mono.just(new CommandResponse<>(command, result)); })); }
@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.")); })); }
@Override public Flux<NumericResponse<KeyCommand, Long>> sCard(Publisher<KeyCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); return cmd.scard(command.getKey()).map(value -> new NumericResponse<>(command, value)); })); }