-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add overloads for XAddOptions in StreamOperations #2936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jinkshower
wants to merge
1
commit into
spring-projects:main
from
jinkshower:add-overloads-for-xaddoptions-in-streamoperations
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand; | ||
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse; | ||
import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions; | ||
import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions; | ||
import org.springframework.data.redis.connection.RedisStreamCommands.XPendingOptions; | ||
import org.springframework.data.redis.connection.stream.ByteBufferRecord; | ||
import org.springframework.data.redis.connection.stream.Consumer; | ||
|
@@ -58,6 +59,7 @@ | |
* @author Tugdual Grall | ||
* @author Dengliming | ||
* @author Mark John Moreno | ||
* @author jinkshower | ||
* @since 2.2 | ||
*/ | ||
public interface ReactiveStreamCommands { | ||
|
@@ -394,11 +396,40 @@ default Mono<RecordId> xAdd(ByteBufferRecord record) { | |
return xAdd(Mono.just(AddStreamRecord.of(record))).next().map(CommandResponse::getOutput); | ||
} | ||
|
||
/** | ||
* Add stream record with the specified options. | ||
* | ||
* @param record must not be {@literal null}. | ||
* @param xAddOptions parameters for the {@literal XADD} call. Must not be {@literal null}. | ||
* @return {@link Mono} the {@link RecordId id}. | ||
* @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> | ||
* @since 3.3 | ||
*/ | ||
default Mono<RecordId> xAdd(ByteBufferRecord record, XAddOptions xAddOptions) { | ||
|
||
Assert.notNull(record, "Record must not be null"); | ||
Assert.notNull(xAddOptions, "XAddOptions must not be null"); | ||
|
||
AddStreamRecord addStreamRecord = AddStreamRecord.of(record) | ||
.approximateTrimming(xAddOptions.isApproximateTrimming()) | ||
.makeNoStream(xAddOptions.isNoMkStream()); | ||
|
||
if (xAddOptions.hasMaxlen()) { | ||
addStreamRecord = addStreamRecord.maxlen(xAddOptions.getMaxlen()); | ||
} | ||
|
||
if (xAddOptions.hasMinId()) { | ||
addStreamRecord = addStreamRecord.minId(xAddOptions.getMinId()); | ||
} | ||
|
||
return xAdd(Mono.just(addStreamRecord)).next().map(CommandResponse::getOutput); | ||
} | ||
|
||
/** | ||
* Add stream record with given {@literal body} to {@literal key}. | ||
* | ||
* @param commands must not be {@literal null}. | ||
* @return {@link Flux} emitting the {@link RecordId} on by for for the given {@link AddStreamRecord} commands. | ||
* @return {@link Flux} emitting the {@link RecordId} on by for the given {@link AddStreamRecord} commands. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed typo |
||
* @see <a href="https://redis.io/commands/xadd">Redis Documentation: XADD</a> | ||
*/ | ||
Flux<CommandResponse<AddStreamRecord, RecordId>> xAdd(Publisher<AddStreamRecord> commands); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason why I wrote somewhat verbose method in here is
unlike
JedisStreamCommands
orLettuceStreamCommands
which both have a method accepting (MapRecord<byte[], byte[], byte[]> record, XAddOptions options)
xAdd(Publisher commands) in
LettuceReactiveStreamCommands
expects that Publisher already has variables of
XAddOptions
.ex) maxlen, isApproxiateTrimming...
so I placed the decapsulation of XAddOptions here.
I thought of changing AddStreamRecord to have variable
priavte final XAddOptions options
so that
LettuceReactiveStreamCommands
can delegate the decapsulation to other classbut I thought this exceeds the scope of this issue.