-
Notifications
You must be signed in to change notification settings - Fork 0
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 XREADGROUP
command
#376
Changes from 5 commits
5a23a1e
7680d68
f861626
2b5abc0
957e012
ffca975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api.models.commands.stream; | ||
|
||
import glide.api.commands.StreamBaseCommands; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
/** | ||
* Optional arguments for {@link StreamBaseCommands#xreadgroup(Map, String, String, | ||
* StreamReadGroupOptions)} | ||
* | ||
* @see <a href="https://valkey.io/commands/xreadgroup/">redis.io</a> | ||
*/ | ||
@SuperBuilder | ||
public final class StreamReadGroupOptions extends StreamReadOptions { | ||
|
||
public static final String READ_GROUP_REDIS_API = "GROUP"; | ||
public static final String READ_NOACK_REDIS_API = "NOACK"; | ||
|
||
/** | ||
* If set, messages are not added to the Pending Entries List (PEL). This is equivalent to | ||
* acknowledging the message when it is read. | ||
*/ | ||
private Boolean noack; | ||
|
||
/** | ||
* Converts options and the key-to-id input for {@link StreamBaseCommands#xreadgroup(Map, String, | ||
* String, StreamReadGroupOptions)} into a String[]. | ||
* | ||
* @return String[] | ||
*/ | ||
public String[] toArgs(String group, String consumer, Map<String, String> streams) { | ||
List<String> optionArgs = new ArrayList<>(); | ||
optionArgs.add(READ_GROUP_REDIS_API); | ||
optionArgs.add(group); | ||
optionArgs.add(consumer); | ||
|
||
if (this.count != null) { | ||
optionArgs.add(READ_COUNT_REDIS_API); | ||
optionArgs.add(count.toString()); | ||
} | ||
|
||
if (this.block != null) { | ||
optionArgs.add(READ_BLOCK_REDIS_API); | ||
optionArgs.add(block.toString()); | ||
} | ||
|
||
if (this.noack != null && this.noack) { | ||
optionArgs.add(READ_NOACK_REDIS_API); | ||
} | ||
|
||
optionArgs.add(READ_STREAMS_REDIS_API); | ||
Set<Map.Entry<String, String>> entrySet = streams.entrySet(); | ||
optionArgs.addAll(entrySet.stream().map(Map.Entry::getKey).collect(Collectors.toList())); | ||
optionArgs.addAll(entrySet.stream().map(Map.Entry::getValue).collect(Collectors.toList())); | ||
|
||
return optionArgs.toArray(new String[0]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import glide.api.models.commands.geospatial.GeospatialData; | ||
import java.lang.reflect.Array; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
@@ -128,7 +129,10 @@ public static <T> Map<String, T[][]> castMapOf2DArray( | |
return null; | ||
} | ||
return mapOfArrays.entrySet().stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, e -> castArrayofArrays(e.getValue(), clazz))); | ||
.collect( | ||
HashMap::new, | ||
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. why this change? to accept nulls? 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. yes. XREADGROUP returns maps will null values (gross!) 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. Do you have a test for that case? 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. I do |
||
(m, e) -> m.put(e.getKey(), castArrayofArrays(e.getValue(), clazz)), | ||
HashMap::putAll); | ||
} | ||
|
||
/** | ||
|
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.
XREADGROUP can/will return null values in the map