forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: Add SADD, SREM, SMEMBERS, and SCARD commands (Set Commands)
- Loading branch information
Showing
8 changed files
with
378 additions
and
2 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
77 changes: 77 additions & 0 deletions
77
java/client/src/main/java/glide/api/commands/SetCommands.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,77 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api.commands; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Set Commands interface. | ||
* | ||
* @see <a href="https://redis.io/commands/?group=set">Set Commands</a> | ||
*/ | ||
public interface SetCommands { | ||
/** | ||
* Add specified members to the set stored at <code>key</code>. Specified members that are already | ||
* a member of this set are ignored. | ||
* | ||
* @see <a href="https://redis.io/commands/sadd/">redis.io</a> for details. | ||
* @param key The <code>key</code> where members will be added to its set. | ||
* @param members A list of members to add to the set stored at <code>key</code>. | ||
* @return The number of members that were added to the set, excluding members already present. | ||
* @remarks If <code>key</code> does not exist, a new set is created before adding <code>members | ||
* </code>. | ||
* @example | ||
* <p><code> | ||
* int result = client.sadd("my_set", new String[]{"member1", "member2"}).get(); | ||
* // result: 2 | ||
* </code> | ||
*/ | ||
CompletableFuture<Long> sadd(String key, String[] members); | ||
|
||
/** | ||
* Remove specified members from the set stored at <code>key</code>. Specified members that are | ||
* not a member of this set are ignored. | ||
* | ||
* @see <a href="https://redis.io/commands/srem/">redis.io</a> for details. | ||
* @param key The <code>key</code> from which members will be removed. | ||
* @param members A list of members to remove from the set stored at <code>key</code>. | ||
* @return The number of members that were removed from the set, excluding non-existing members. | ||
* @remarks If <code>key</code> does not exist, it is treated as an empty set and this command | ||
* returns 0. | ||
* @example | ||
* <p><code> | ||
* int result = client.srem("my_set", new String[]{"member1", "member2"}).get(); | ||
* // result: 2 | ||
* </code> | ||
*/ | ||
CompletableFuture<Long> srem(String key, String[] members); | ||
|
||
/** | ||
* Retrieve all the members of the set value stored at <code>key</code>. | ||
* | ||
* @see <a href="https://redis.io/commands/smembers/">redis.io</a> for details. | ||
* @param key The key from which to retrieve the set members. | ||
* @return A <code>Set</code> of all members of the set. | ||
* @remarks If <code>key</code> does not exist an empty set will be returned. | ||
* @example | ||
* <p><code> | ||
* {@literal Set<String>} result = client.smembers("my_set").get(); | ||
* // result: {"member1", "member2", "member3"} | ||
* </code> | ||
*/ | ||
CompletableFuture<Set<String>> smembers(String key); | ||
|
||
/** | ||
* Retrieve the set cardinality (number of elements) of the set stored at <code>key</code>. | ||
* | ||
* @see <a href="https://redis.io/commands/scard/">redis.io</a> for details. | ||
* @param key The key from which to retrieve the number of set members. | ||
* @return The cardinality (number of elements) of the set, or 0 if the key does not exist. | ||
* @example | ||
* <p><code> | ||
* int result = client.scard("my_set").get(); | ||
* // result: 3 | ||
* </code> | ||
*/ | ||
CompletableFuture<Long> scard(String key); | ||
} |
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
Oops, something went wrong.