-
Notifications
You must be signed in to change notification settings - Fork 59
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
Java: Add the XRANGE command #1501
Merged
acarbonetto
merged 4 commits into
valkey-io:main
from
Bit-Quill:java/integ_acarbo_add_xrange_command
May 31, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -197,6 +197,7 @@ enum RequestType { | |
XLen = 159; | ||
LSet = 165; | ||
XDel = 166; | ||
XRange = 167; | ||
LMove = 168; | ||
} | ||
|
||
|
This file contains 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 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 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 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
114 changes: 114 additions & 0 deletions
114
java/client/src/main/java/glide/api/models/commands/stream/StreamRange.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api.models.commands.stream; | ||
|
||
import glide.utils.ArrayTransformUtils; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Arguments for {@link glide.api.commands.StreamBaseCommands#xrange} and {@link | ||
* glide.api.commands.StreamBaseCommands#xrevrange} to specify the starting and ending range for the | ||
* stream search by stream ID. | ||
* | ||
* @see <a href="https://redis.io/commands/xrange/">redis.io</a> | ||
* @see <a href="https://redis.io/commands/xrevrange/">redis.io</a> | ||
*/ | ||
public interface StreamRange { | ||
|
||
String getRedisApi(); | ||
|
||
String MINIMUM_RANGE_REDIS_API = "-"; | ||
String MAXIMUM_RANGE_REDIS_API = "+"; | ||
String RANGE_COUNT_REDIS_API = "COUNT"; | ||
|
||
/** | ||
* Enumeration representing minimum or maximum stream entry bounds for the range search, to get | ||
* the first or last stream ID. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
enum InfRangeBound implements StreamRange { | ||
MIN(MINIMUM_RANGE_REDIS_API), | ||
MAX(MAXIMUM_RANGE_REDIS_API); | ||
|
||
private final String redisApi; | ||
}; | ||
|
||
/** | ||
* Stream ID used to specify a range of IDs to search. Stream ID bounds can be complete with a | ||
* timestamp and sequence number separated by a dash (<code>"-"</code>), for example <code> | ||
* "1526985054069-0"</code>.<br> | ||
* Stream ID bounds can also be incomplete, with just a timestamp.<br> | ||
* Stream ID bounds are inclusive by default. When <code>isInclusive==false</code>, a <code>"(" | ||
* </code> is prepended for the Redis API. | ||
*/ | ||
@Getter | ||
class IdBound implements StreamRange { | ||
private final String redisApi; | ||
|
||
/** | ||
* Default constructor | ||
* | ||
* @param id The stream id. | ||
*/ | ||
private IdBound(String id) { | ||
redisApi = id; | ||
} | ||
|
||
/** | ||
* Creates a stream ID boundary by stream id for range search. | ||
* | ||
* @param id The stream id. | ||
*/ | ||
public static IdBound of(String id) { | ||
return new IdBound(id); | ||
} | ||
|
||
/** | ||
* Creates an incomplete stream ID boundary without the sequence number for range search. | ||
* | ||
* @param timestamp The stream timestamp as ID. | ||
*/ | ||
public static IdBound of(long timestamp) { | ||
return new IdBound(Long.toString(timestamp)); | ||
} | ||
|
||
/** | ||
* Creates an incomplete stream ID exclusive boundary without the sequence number for range | ||
* search. | ||
* | ||
* @param timestamp The stream timestamp as ID. | ||
*/ | ||
public static IdBound ofExclusive(long timestamp) { | ||
return new IdBound("(" + timestamp); | ||
} | ||
|
||
/** | ||
* Creates a stream ID exclusive boundary by stream id for range search. | ||
* | ||
* @param id The stream id. | ||
*/ | ||
public static IdBound ofExclusive(String id) { | ||
return new IdBound("(" + id); | ||
} | ||
} | ||
|
||
/** | ||
* Convert StreamRange arguments to a string array | ||
* | ||
* @return arguments converted to an array to be consumed by Redis | ||
*/ | ||
static String[] toArgs(StreamRange start, StreamRange end) { | ||
return new String[] {start.getRedisApi(), end.getRedisApi()}; | ||
} | ||
|
||
/** | ||
* Convert StreamRange arguments to a string array | ||
* | ||
* @return arguments converted to an array to be consumed by Redis | ||
*/ | ||
static String[] toArgs(StreamRange start, StreamRange end, long count) { | ||
return ArrayTransformUtils.concatenateArrays( | ||
toArgs(start, end), new String[] {RANGE_COUNT_REDIS_API, Long.toString(count)}); | ||
} | ||
} |
Oops, something went wrong.
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.
probably small enough to sneak in but was this intentional? changes on another command?
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.
Yes. This was an intentionally sneaky move...