forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: Added Mget and Mset commands to BaseClient and BaseTransactions…
…. (String Commands) (valkey-io#955) * Added Mget and Mset commands. (valkey-io#78) * Added Mget and Mset commands to BaseClient and BaseTransactions. * Added 2 util functions for code cleanup. Minor documentation refactor. * Added transaction tests. * Added documentation for CommandUtils. * Minor changes based on PR comments * Minor changes based on PR comments * Fix merge conflicts; spotless Signed-off-by: Andrew Carbonetto <[email protected]> * Minor changes from PR comments. * Reorder commands Signed-off-by: Andrew Carbonetto <[email protected]> * Spotless. --------- Signed-off-by: Andrew Carbonetto <[email protected]> Co-authored-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
66793f2
commit a1facbf
Showing
9 changed files
with
223 additions
and
8 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
37 changes: 37 additions & 0 deletions
37
java/client/src/main/java/glide/utils/ArrayTransformUtils.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,37 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.utils; | ||
|
||
import java.lang.reflect.Array; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class ArrayTransformUtils { | ||
|
||
/** | ||
* Converts a map to an array of strings with alternating keys and values. | ||
* | ||
* @param args Map of string pairs to convert. | ||
* @return Array of strings [key1, value1, key2, value2, ...]. | ||
*/ | ||
public static String[] convertMapToArgArray(Map<String, String> args) { | ||
return args.entrySet().stream() | ||
.flatMap(entry -> Stream.of(entry.getKey(), entry.getValue())) | ||
.toArray(String[]::new); | ||
} | ||
|
||
/** | ||
* Casts an array of objects to an array of type T. | ||
* | ||
* @param objectArr Array of objects to cast. | ||
* @param clazz The class of the array elements to cast to. | ||
* @return An array of type T, containing the elements from the input array. | ||
* @param <T> The type to which the elements are cast. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <T, U extends T> U[] castArray(T[] objectArr, Class<U> clazz) { | ||
return Arrays.stream(objectArr) | ||
.map(clazz::cast) | ||
.toArray(size -> (U[]) Array.newInstance(clazz, size)); | ||
} | ||
} |
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