|
26 | 26 | import org.springframework.data.domain.Range;
|
27 | 27 | import org.springframework.data.redis.connection.Limit;
|
28 | 28 | import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions;
|
| 29 | +import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions; |
29 | 30 | import org.springframework.data.redis.connection.stream.ByteBufferRecord;
|
30 | 31 | import org.springframework.data.redis.connection.stream.Consumer;
|
31 | 32 | import org.springframework.data.redis.connection.stream.MapRecord;
|
|
54 | 55 | * @author Dengliming
|
55 | 56 | * @author Marcin Zielinski
|
56 | 57 | * @author John Blum
|
| 58 | + * @author jinkshower |
57 | 59 | * @since 2.2
|
58 | 60 | */
|
59 | 61 | public interface ReactiveStreamOperations<K, HK, HV> extends HashMapperProvider<HK, HV> {
|
@@ -94,6 +96,63 @@ default Mono<Long> acknowledge(String group, Record<K, ?> record) {
|
94 | 96 | return acknowledge(record.getRequiredStream(), group, record.getId());
|
95 | 97 | }
|
96 | 98 |
|
| 99 | + /** |
| 100 | + * Append one or more records to the stream {@code key} with the specified options. |
| 101 | + * |
| 102 | + * @param key the stream key. |
| 103 | + * @param bodyPublisher record body {@link Publisher}. |
| 104 | + * @param xAddOptions parameters for the {@literal XADD} call. |
| 105 | + * @return the record Ids. |
| 106 | + * @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> |
| 107 | + * @since 3.3 |
| 108 | + */ |
| 109 | + default Flux<RecordId> add (K key, Publisher<? extends Map<? extends HK, ? extends HV>> bodyPublisher, |
| 110 | + XAddOptions xAddOptions) { |
| 111 | + return Flux.from(bodyPublisher).flatMap(it -> add(key, it, xAddOptions)); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Append a record to the stream {@code key} with the specified options. |
| 116 | + * |
| 117 | + * @param key the stream key. |
| 118 | + * @param content record content as Map. |
| 119 | + * @param xAddOptions parameters for the {@literal XADD} call. |
| 120 | + * @return the {@link Mono} emitting the {@link RecordId}. |
| 121 | + * @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> |
| 122 | + * @since 3.3 |
| 123 | + */ |
| 124 | + default Mono<RecordId> add(K key, Map<? extends HK, ? extends HV> content, XAddOptions xAddOptions) { |
| 125 | + return add(StreamRecords.newRecord().in(key).ofMap(content), xAddOptions); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Append a record, backed by a {@link Map} holding the field/value pairs, to the stream with the specified options. |
| 130 | + * |
| 131 | + * @param record the record to append. |
| 132 | + * @param xAddOptions parameters for the {@literal XADD} call. |
| 133 | + * @return the {@link Mono} emitting the {@link RecordId}. |
| 134 | + * @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> |
| 135 | + * @since 3.3 |
| 136 | + */ |
| 137 | + @SuppressWarnings("unchecked") |
| 138 | + default Mono<RecordId> add(MapRecord<K, ? extends HK, ? extends HV> record, XAddOptions xAddOptions) { |
| 139 | + return add((Record) record, xAddOptions); |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Append the record, backed by the given value, to the stream with the specified options. |
| 144 | + * The value will be hashed and serialized. |
| 145 | + * |
| 146 | + * @param record must not be {@literal null}. |
| 147 | + * @param xAddOptions parameters for the {@literal XADD} call. Must not be {@literal null}. |
| 148 | + * @return the {@link Mono} emitting the {@link RecordId}. |
| 149 | + * @see MapRecord |
| 150 | + * @see ObjectRecord |
| 151 | + * @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> |
| 152 | + * @since 3.3 |
| 153 | + */ |
| 154 | + Mono<RecordId> add(Record<K, ?> record, XAddOptions xAddOptions); |
| 155 | + |
97 | 156 | /**
|
98 | 157 | * Append one or more records to the stream {@code key}.
|
99 | 158 | *
|
|
0 commit comments