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