-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into node/integ_acongo_linsert
- Loading branch information
Showing
17 changed files
with
630 additions
and
39 deletions.
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
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
61 changes: 61 additions & 0 deletions
61
java/client/src/main/java/glide/api/models/commands/stream/StreamReadOptions.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,61 @@ | ||
/** 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.Builder; | ||
|
||
/** | ||
* Optional arguments for {@link StreamBaseCommands#xread(Map, StreamReadOptions)} | ||
* | ||
* @see <a href="https://redis.io/commands/xread/">redis.io</a> | ||
*/ | ||
@Builder | ||
public final class StreamReadOptions { | ||
|
||
public static final String READ_COUNT_REDIS_API = "COUNT"; | ||
public static final String READ_BLOCK_REDIS_API = "BLOCK"; | ||
public static final String READ_STREAMS_REDIS_API = "STREAMS"; | ||
|
||
/** | ||
* If set, the request will be blocked for the set amount of milliseconds or until the server has | ||
* the required number of entries. Equivalent to <code>BLOCK</code> in the Redis API. | ||
*/ | ||
Long block; | ||
|
||
/** | ||
* The maximal number of elements requested. Equivalent to <code>COUNT</code> in the Redis API. | ||
*/ | ||
Long count; | ||
|
||
/** | ||
* Converts options and the key-to-id input for {@link StreamBaseCommands#xread(Map, | ||
* StreamReadOptions)} into a String[]. | ||
* | ||
* @return String[] | ||
*/ | ||
public String[] toArgs(Map<String, String> streams) { | ||
List<String> optionArgs = new ArrayList<>(); | ||
|
||
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()); | ||
} | ||
|
||
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]); | ||
} | ||
} |
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
Oops, something went wrong.