Package glide.api.commands
Interface SetBaseCommands
-
- All Known Implementing Classes:
BaseClient,GlideClient,GlideClusterClient
public interface SetBaseCommandsSupports commands for the "Set Commands" group for standalone and cluster clients.- See Also:
- Set Commands
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSET_LIMIT_VALKEY_APIValkey API keyword used to limit calculation of intersection of sorted sets.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Long>sadd(GlideString key, GlideString[] members)Adds specified members to the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>sadd(java.lang.String key, java.lang.String[] members)Adds specified members to the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>scard(GlideString key)Retrieves the set cardinality (number of elements) of the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>scard(java.lang.String key)Retrieves the set cardinality (number of elements) of the set stored atkey.java.util.concurrent.CompletableFuture<java.util.Set<GlideString>>sdiff(GlideString[] keys)Computes the difference between the first set and all the successive sets inkeys.java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>>sdiff(java.lang.String[] keys)Computes the difference between the first set and all the successive sets inkeys.java.util.concurrent.CompletableFuture<java.lang.Long>sdiffstore(GlideString destination, GlideString[] keys)Stores the difference between the first set and all the successive sets inkeysinto a new set atdestination.java.util.concurrent.CompletableFuture<java.lang.Long>sdiffstore(java.lang.String destination, java.lang.String[] keys)Stores the difference between the first set and all the successive sets inkeysinto a new set atdestination.java.util.concurrent.CompletableFuture<java.util.Set<GlideString>>sinter(GlideString[] keys)Gets the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>>sinter(java.lang.String[] keys)Gets the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sintercard(GlideString[] keys)Gets the cardinality of the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sintercard(GlideString[] keys, long limit)Gets the cardinality of the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sintercard(java.lang.String[] keys)Gets the cardinality of the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sintercard(java.lang.String[] keys, long limit)Gets the cardinality of the intersection of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sinterstore(GlideString destination, GlideString[] keys)Stores the members of the intersection of all given sets specified bykeysinto a new set atdestination.java.util.concurrent.CompletableFuture<java.lang.Long>sinterstore(java.lang.String destination, java.lang.String[] keys)Stores the members of the intersection of all given sets specified bykeysinto a new set atdestination.java.util.concurrent.CompletableFuture<java.lang.Boolean>sismember(GlideString key, GlideString member)Returns ifmemberis a member of the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>sismember(java.lang.String key, java.lang.String member)Returns ifmemberis a member of the set stored atkey.java.util.concurrent.CompletableFuture<java.util.Set<GlideString>>smembers(GlideString key)Retrieves all the members of the set value stored atkey.java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>>smembers(java.lang.String key)Retrieves all the members of the set value stored atkey.java.util.concurrent.CompletableFuture<java.lang.Boolean[]>smismember(GlideString key, GlideString[] members)Checks whether each member is contained in the members of the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Boolean[]>smismember(java.lang.String key, java.lang.String[] members)Checks whether each member is contained in the members of the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>smove(GlideString source, GlideString destination, GlideString member)Movesmemberfrom the set atsourceto the set atdestination, removing it from the source set.java.util.concurrent.CompletableFuture<java.lang.Boolean>smove(java.lang.String source, java.lang.String destination, java.lang.String member)Movesmemberfrom the set atsourceto the set atdestination, removing it from the source set.java.util.concurrent.CompletableFuture<GlideString>spop(GlideString key)Removes and returns one random member from the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.String>spop(java.lang.String key)Removes and returns one random member from the set stored atkey.java.util.concurrent.CompletableFuture<java.util.Set<GlideString>>spopCount(GlideString key, long count)Removes and returns up tocountrandom members from the set stored atkey, depending on the set's length.java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>>spopCount(java.lang.String key, long count)Removes and returns up tocountrandom members from the set stored atkey, depending on the set's length.java.util.concurrent.CompletableFuture<GlideString>srandmember(GlideString key)Returns a random element from the set value stored atkey.java.util.concurrent.CompletableFuture<GlideString[]>srandmember(GlideString key, long count)Returns one or more random elements from the set value stored atkey.java.util.concurrent.CompletableFuture<java.lang.String>srandmember(java.lang.String key)Returns a random element from the set value stored atkey.java.util.concurrent.CompletableFuture<java.lang.String[]>srandmember(java.lang.String key, long count)Returns one or more random elements from the set value stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>srem(GlideString key, GlideString[] members)Removes specified members from the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>srem(java.lang.String key, java.lang.String[] members)Removes specified members from the set stored atkey.java.util.concurrent.CompletableFuture<java.lang.Object[]>sscan(GlideString key, GlideString cursor)Iterates incrementally over a set.java.util.concurrent.CompletableFuture<java.lang.Object[]>sscan(GlideString key, GlideString cursor, SScanOptionsBinary sScanOptions)Iterates incrementally over a set.java.util.concurrent.CompletableFuture<java.lang.Object[]>sscan(java.lang.String key, java.lang.String cursor)Iterates incrementally over a set.java.util.concurrent.CompletableFuture<java.lang.Object[]>sscan(java.lang.String key, java.lang.String cursor, SScanOptions sScanOptions)Iterates incrementally over a set.java.util.concurrent.CompletableFuture<java.util.Set<GlideString>>sunion(GlideString[] keys)Gets the union of all the given sets.java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>>sunion(java.lang.String[] keys)Gets the union of all the given sets.java.util.concurrent.CompletableFuture<java.lang.Long>sunionstore(GlideString destination, GlideString[] keys)Stores the members of the union of all given sets specified bykeysinto a new set atdestination.java.util.concurrent.CompletableFuture<java.lang.Long>sunionstore(java.lang.String destination, java.lang.String[] keys)Stores the members of the union of all given sets specified bykeysinto a new set atdestination.
-
-
-
Field Detail
-
SET_LIMIT_VALKEY_API
static final java.lang.String SET_LIMIT_VALKEY_API
Valkey API keyword used to limit calculation of intersection of sorted sets.- See Also:
- Constant Field Values
-
-
Method Detail
-
sadd
java.util.concurrent.CompletableFuture<java.lang.Long> sadd(java.lang.String key, java.lang.String[] members)Adds specified members to the set stored atkey. Specified members that are already a member of this set are ignored.- Parameters:
key- Thekeywhere members will be added to its set.members- A list of members to add to the set stored atkey.- Returns:
- The number of members that were added to the set, excluding members already present.
- See Also:
- valkey.io for details.
- Example:
Long result = client.sadd("my_set", new String[]{"member1", "member2"}).get(); assert result == 2L;
-
sadd
java.util.concurrent.CompletableFuture<java.lang.Long> sadd(GlideString key, GlideString[] members)
Adds specified members to the set stored atkey. Specified members that are already a member of this set are ignored.- Parameters:
key- Thekeywhere members will be added to its set.members- A list of members to add to the set stored atkey.- Returns:
- The number of members that were added to the set, excluding members already present.
- See Also:
- valkey.io for details.
- Example:
Long result = client.sadd(gs("my_set"), new GlideString[]{gs("member1"), gs("member2")}).get(); assert result == 2L;
-
srem
java.util.concurrent.CompletableFuture<java.lang.Long> srem(java.lang.String key, java.lang.String[] members)Removes specified members from the set stored atkey. Specified members that are not a member of this set are ignored.- Parameters:
key- Thekeyfrom which members will be removed.members- A list of members to remove from the set stored atkey.- Returns:
- The number of members that were removed from the set, excluding non-existing members.
- See Also:
- valkey.io for details.
- Example:
Long result = client.srem("my_set", new String[]{"member1", "member2"}).get(); assert result == 2L;
-
srem
java.util.concurrent.CompletableFuture<java.lang.Long> srem(GlideString key, GlideString[] members)
Removes specified members from the set stored atkey. Specified members that are not a member of this set are ignored.- Parameters:
key- Thekeyfrom which members will be removed.members- A list of members to remove from the set stored atkey.- Returns:
- The number of members that were removed from the set, excluding non-existing members.
- See Also:
- valkey.io for details.
- Example:
Long result = client.srem(gs("my_set"), new GlideString[]{gs("member1"), gs("member2")}).get(); assert result == 2L;
-
smembers
java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>> smembers(java.lang.String key)
Retrieves all the members of the set value stored atkey.- Parameters:
key- The key from which to retrieve the set members.- Returns:
- A
Setof all members of the set. - See Also:
- valkey.io for details.
- Example:
Set<String> result = client.smembers("my_set").get(); assert result.equals(Set.of("member1", "member2", "member3"));
-
smembers
java.util.concurrent.CompletableFuture<java.util.Set<GlideString>> smembers(GlideString key)
Retrieves all the members of the set value stored atkey.- Parameters:
key- The key from which to retrieve the set members.- Returns:
- A
Setof all members of the set. - See Also:
- valkey.io for details.
- Example:
Set<String> result = client.smembers(gs("my_set")).get(); assert result.equals(Set.of(gs("member1"), gs("member2"), gs("member3")));
-
scard
java.util.concurrent.CompletableFuture<java.lang.Long> scard(java.lang.String key)
Retrieves the set cardinality (number of elements) of the set stored atkey.- Parameters:
key- The key from which to retrieve the number of set members.- Returns:
- The cardinality (number of elements) of the set, or 0 if the key does not exist.
- See Also:
- valkey.io for details.
- Example:
Long result = client.scard("my_set").get(); assert result == 3L;
-
scard
java.util.concurrent.CompletableFuture<java.lang.Long> scard(GlideString key)
Retrieves the set cardinality (number of elements) of the set stored atkey.- Parameters:
key- The key from which to retrieve the number of set members.- Returns:
- The cardinality (number of elements) of the set, or 0 if the key does not exist.
- See Also:
- valkey.io for details.
- Example:
Long result = client.scard("my_set").get(); assert result == 3L;
-
smismember
java.util.concurrent.CompletableFuture<java.lang.Boolean[]> smismember(java.lang.String key, java.lang.String[] members)Checks whether each member is contained in the members of the set stored atkey.- Parameters:
key- The key of the set to check.members- A list of members to check for existence in the set.- Returns:
- An
arrayofBooleanvalues, each indicating if the respective member exists in the set. - See Also:
- valkey.io for details.
- Example:
Boolean[] areMembers = client.smismembmer("my_set", new String[] { "a", "b", "c" }).get(); assert areMembers[0] && areMembers[1] && !areMembers[2]; // Only first two elements are present in "my_set"
-
smismember
java.util.concurrent.CompletableFuture<java.lang.Boolean[]> smismember(GlideString key, GlideString[] members)
Checks whether each member is contained in the members of the set stored atkey.- Parameters:
key- The key of the set to check.members- A list of members to check for existence in the set.- Returns:
- An
arrayofBooleanvalues, each indicating if the respective member exists in the set. - See Also:
- valkey.io for details.
- Example:
Boolean[] areMembers = client.smismembmer(gs("my_set"), new GlideString[] { gs("a"), gs("b"), gs("c") }).get(); assert areMembers[0] && areMembers[1] && !areMembers[2]; // Only first two elements are present in "my_set"
-
smove
java.util.concurrent.CompletableFuture<java.lang.Boolean> smove(java.lang.String source, java.lang.String destination, java.lang.String member)Movesmemberfrom the set atsourceto the set atdestination, removing it from the source set. Creates a new destination set if needed. The operation is atomic.- Parameters:
source- The key of the set to remove the element from.destination- The key of the set to add the element to.member- The set element to move.- Returns:
trueon success, orfalseif thesourceset does not exist or the element is not a member of the source set.- See Also:
- valkey.io for details.
- Example:
Boolean moved = client.smove("set1", "set2", "element").get(); assert moved;
-
smove
java.util.concurrent.CompletableFuture<java.lang.Boolean> smove(GlideString source, GlideString destination, GlideString member)
Movesmemberfrom the set atsourceto the set atdestination, removing it from the source set. Creates a new destination set if needed. The operation is atomic.- Parameters:
source- The key of the set to remove the element from.destination- The key of the set to add the element to.member- The set element to move.- Returns:
trueon success, orfalseif thesourceset does not exist or the element is not a member of the source set.- See Also:
- valkey.io for details.
- Example:
Boolean moved = client.smove(gs("set1"), gs("set2"), gs("element")).get(); assert moved;
-
sismember
java.util.concurrent.CompletableFuture<java.lang.Boolean> sismember(java.lang.String key, java.lang.String member)Returns ifmemberis a member of the set stored atkey.- Parameters:
key- The key of the set.member- The member to check for existence in the set.- Returns:
trueif the member exists in the set,falseotherwise. Ifkeydoesn't exist, it is treated as anempty setand the command returnsfalse.- See Also:
- valkey.io for details.
- Example:
Boolean payload1 = client.sismember("mySet", "member1").get(); assert payload1; // Indicates that "member1" exists in the set "mySet". Boolean payload2 = client.sismember("mySet", "nonExistingMember").get(); assert !payload2; // Indicates that "nonExistingMember" does not exist in the set "mySet".
-
sismember
java.util.concurrent.CompletableFuture<java.lang.Boolean> sismember(GlideString key, GlideString member)
Returns ifmemberis a member of the set stored atkey.- Parameters:
key- The key of the set.member- The member to check for existence in the set.- Returns:
trueif the member exists in the set,falseotherwise. Ifkeydoesn't exist, it is treated as anempty setand the command returnsfalse.- See Also:
- valkey.io for details.
- Example:
Boolean payload1 = client.sismember(gs("mySet"), gs("member1")).get(); assert payload1; // Indicates that "member1" exists in the set "mySet". Boolean payload2 = client.sismember(gs("mySet"), gs("nonExistingMember")).get(); assert !payload2; // Indicates that "nonExistingMember" does not exist in the set "mySet".
-
sdiff
java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>> sdiff(java.lang.String[] keys)
Computes the difference between the first set and all the successive sets inkeys.- Parameters:
keys- The keys of the sets to diff.- Returns:
- A
Setof elements representing the difference between the sets.
If the akeydoes not exist, it is treated as an empty set. - See Also:
- valkey.io for details.
- Example:
Set<String> values = client.sdiff(new String[] {"set1", "set2"}).get(); assert values.contains("element"); // Indicates that "element" is present in "set1", but missing in "set2"
-
sdiff
java.util.concurrent.CompletableFuture<java.util.Set<GlideString>> sdiff(GlideString[] keys)
Computes the difference between the first set and all the successive sets inkeys.- Parameters:
keys- The keys of the sets to diff.- Returns:
- A
Setof elements representing the difference between the sets.
If the akeydoes not exist, it is treated as an empty set. - See Also:
- valkey.io for details.
- Example:
Set<GlideString> values = client.sdiff(new GlideString[] {gs("set1"), gs("set2")}).get(); assert values.contains(gs("element")); // Indicates that "element" is present in "set1", but missing in "set2"
-
sdiffstore
java.util.concurrent.CompletableFuture<java.lang.Long> sdiffstore(java.lang.String destination, java.lang.String[] keys)Stores the difference between the first set and all the successive sets inkeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys of the sets to diff.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sdiffstore("mySet", new String[] { "set1", "set2" }).get(); assert length == 5L;
-
sdiffstore
java.util.concurrent.CompletableFuture<java.lang.Long> sdiffstore(GlideString destination, GlideString[] keys)
Stores the difference between the first set and all the successive sets inkeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys of the sets to diff.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sdiffstore(gs("mySet"), new GlideString[] { gs("set1"), gs("set2") }).get(); assert length == 5L;
-
sinter
java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>> sinter(java.lang.String[] keys)
Gets the intersection of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- A
Setof members which are present in all given sets.
If one or more sets do not exist, an empty set will be returned. - See Also:
- valkey.io for details.
- Example:
Set<String> values = client.sinter(new String[] {"set1", "set2"}).get(); assert values.contains("element"); // Indicates that these sets have a common element Set<String> values = client.sinter(new String[] {"set1", "nonExistingSet"}).get(); assert values.size() == 0;
-
sinter
java.util.concurrent.CompletableFuture<java.util.Set<GlideString>> sinter(GlideString[] keys)
Gets the intersection of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- A
Setof members which are present in all given sets.
If one or more sets do not exist, an empty set will be returned. - See Also:
- valkey.io for details.
- Example:
Set<GlideString> values = client.sinter(new GlideString[] {gs("set1"), gs("set2")}).get(); assert values.contains(gs("element")); // Indicates that these sets have a common element Set<GlideString> values = client.sinter(new GlideString[] {gs("set1"), gs("nonExistingSet")}).get(); assert values.size() == 0;
-
sintercard
java.util.concurrent.CompletableFuture<java.lang.Long> sintercard(java.lang.String[] keys)
Gets the cardinality of the intersection of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- The cardinality of the intersection result. If one or more sets do not exist,
0is returned. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long response = client.sintercard(new String[] {"set1", "set2"}).get(); assertEquals(2L, response); Long emptyResponse = client.sintercard(new String[] {"set1", "nonExistingSet"}).get(); assertEquals(emptyResponse, 0L);
-
sintercard
java.util.concurrent.CompletableFuture<java.lang.Long> sintercard(GlideString[] keys)
Gets the cardinality of the intersection of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- The cardinality of the intersection result. If one or more sets do not exist,
0is returned. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long response = client.sintercard(new GlideString[] {gs("set1"), gs("set2")}).get(); assertEquals(2L, response); Long emptyResponse = client.sintercard(new GlideString[] {gs("set1"), gs("nonExistingSet")}).get(); assertEquals(emptyResponse, 0L);
-
sintercard
java.util.concurrent.CompletableFuture<java.lang.Long> sintercard(java.lang.String[] keys, long limit)Gets the cardinality of the intersection of all the given sets.- Parameters:
keys- The keys of the sets.limit- The limit for the intersection cardinality value.- Returns:
- The cardinality of the intersection result. If one or more sets do not exist,
0is returned. If the intersection cardinality reacheslimitpartway through the computation, returnslimitas the cardinality. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long response = client.sintercard(new String[] {"set1", "set2"}, 3).get(); assertEquals(2L, response); Long emptyResponse = client.sintercard(new String[] {"set1", "nonExistingSet"}, 3).get(); assertEquals(emptyResponse, 0L); // when intersection cardinality > limit, returns limit as cardinality Long response2 = client.sintercard(new String[] {"set3", "set4"}, 3).get(); assertEquals(3L, response2);
-
sintercard
java.util.concurrent.CompletableFuture<java.lang.Long> sintercard(GlideString[] keys, long limit)
Gets the cardinality of the intersection of all the given sets.- Parameters:
keys- The keys of the sets.limit- The limit for the intersection cardinality value.- Returns:
- The cardinality of the intersection result. If one or more sets do not exist,
0is returned. If the intersection cardinality reacheslimitpartway through the computation, returnslimitas the cardinality. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long response = client.sintercard(new GlideString[] {gs("set1"), gs("set2")}, 3).get(); assertEquals(2L, response); Long emptyResponse = client.sintercard(new GlideString[] {gs("set1"), gs("nonExistingSet")}, 3).get(); assertEquals(emptyResponse, 0L); // when intersection cardinality > limit, returns limit as cardinality Long response2 = client.sintercard(new GlideString[] {gs("set3"), gs("set4")}, 3).get(); assertEquals(3L, response2);
-
sinterstore
java.util.concurrent.CompletableFuture<java.lang.Long> sinterstore(java.lang.String destination, java.lang.String[] keys)Stores the members of the intersection of all given sets specified bykeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys from which to retrieve the set members.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sinterstore("mySet", new String[] { "set1", "set2" }).get(); assert length == 5L;
-
sinterstore
java.util.concurrent.CompletableFuture<java.lang.Long> sinterstore(GlideString destination, GlideString[] keys)
Stores the members of the intersection of all given sets specified bykeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys from which to retrieve the set members.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sinterstore(gs("mySet"), new GlideString[] { gs("set1"), gs("set2") }).get(); assert length == 5L;
-
sunionstore
java.util.concurrent.CompletableFuture<java.lang.Long> sunionstore(java.lang.String destination, java.lang.String[] keys)Stores the members of the union of all given sets specified bykeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys from which to retrieve the set members.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sunionstore("mySet", new String[] { "set1", "set2" }).get(); assert length == 5L;
-
sunionstore
java.util.concurrent.CompletableFuture<java.lang.Long> sunionstore(GlideString destination, GlideString[] keys)
Stores the members of the union of all given sets specified bykeysinto a new set atdestination.- Parameters:
destination- The key of the destination set.keys- The keys from which to retrieve the set members.- Returns:
- The number of elements in the resulting set.
- See Also:
- valkey.io for details.
- Example:
Long length = client.sunionstore(gs("mySet"), new GlideString[] { gs("set1"), gs("set2") }).get(); assert length == 5L;
-
srandmember
java.util.concurrent.CompletableFuture<java.lang.String> srandmember(java.lang.String key)
Returns a random element from the set value stored atkey.- Parameters:
key- The key from which to retrieve the set member.- Returns:
- A random element from the set, or
nullifkeydoes not exist. - See Also:
- valkey.io for details.
- Example:
client.sadd("test", new String[] {"one"}).get(); String response = client.srandmember("test").get(); assertEquals("one", response);
-
srandmember
java.util.concurrent.CompletableFuture<GlideString> srandmember(GlideString key)
Returns a random element from the set value stored atkey.- Parameters:
key- The key from which to retrieve the set member.- Returns:
- A random element from the set, or
nullifkeydoes not exist. - See Also:
- valkey.io for details.
- Example:
client.sadd(gs("test"), new GlideString[] {gs("one")}).get(); GlideString response = client.srandmember(gs("test")).get(); assertEquals(gs("one"), response);
-
srandmember
java.util.concurrent.CompletableFuture<java.lang.String[]> srandmember(java.lang.String key, long count)Returns one or more random elements from the set value stored atkey.- Parameters:
key- The key from which to retrieve the set members.count- The number of elements to return.
Ifcountis positive, returns unique elements.
If negative, allows for duplicates.- Returns:
- An
arrayof elements from the set, or an emptyarrayifkeydoes not exist. - See Also:
- valkey.io for details.
- Example:
client.sadd("test", new String[] {"one"}).get(); String[] response = client.srandmember("test", -2).get(); assertArrayEquals(new String[] {"one", "one"}, response);
-
srandmember
java.util.concurrent.CompletableFuture<GlideString[]> srandmember(GlideString key, long count)
Returns one or more random elements from the set value stored atkey.- Parameters:
key- The key from which to retrieve the set members.count- The number of elements to return.
Ifcountis positive, returns unique elements.
If negative, allows for duplicates.- Returns:
- An
arrayof elements from the set, or an emptyarrayifkeydoes not exist. - See Also:
- valkey.io for details.
- Example:
client.sadd(gs("test"), new GlideString[] {gs("one")}).get(); GlideString[] response = client.srandmember(gs("test"), -2).get(); assertArrayEquals(new GlideString[] {gs("one"), gs("one")}, response);
-
spop
java.util.concurrent.CompletableFuture<java.lang.String> spop(java.lang.String key)
Removes and returns one random member from the set stored atkey.- Parameters:
key- The key of the set.- Returns:
- The value of the popped member.
Ifkeydoes not exist,nullwill be returned. - See Also:
- valkey.io for details.
- Example:
String value1 = client.spop("mySet").get(); assert value1.equals("value1"); String value2 = client.spop("nonExistingSet").get(); assert value2.equals(null);
-
spop
java.util.concurrent.CompletableFuture<GlideString> spop(GlideString key)
Removes and returns one random member from the set stored atkey.- Parameters:
key- The key of the set.- Returns:
- The value of the popped member.
Ifkeydoes not exist,nullwill be returned. - See Also:
- valkey.io for details.
- Example:
GlideString value1 = client.spop(gs("mySet")).get(); assert value1.equals(gs("value1")); GlideString value2 = client.spop(gs("nonExistingSet")).get(); assert value2.equals(null);
-
spopCount
java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>> spopCount(java.lang.String key, long count)Removes and returns up tocountrandom members from the set stored atkey, depending on the set's length.- Parameters:
key- The key of the set.count- The count of the elements to pop from the set.- Returns:
- A set of popped elements will be returned depending on the set's length.
Ifkeydoes not exist, an emptySetwill be returned. - See Also:
- valkey.io for details.
- Example:
Set<String> values1 = client.spopCount("mySet", 2).get(); assert values1.equals(new String[] {"value1", "value2"}); Set<String> values2 = client.spopCount("nonExistingSet", 2).get(); assert values2.size() == 0;
-
spopCount
java.util.concurrent.CompletableFuture<java.util.Set<GlideString>> spopCount(GlideString key, long count)
Removes and returns up tocountrandom members from the set stored atkey, depending on the set's length.- Parameters:
key- The key of the set.count- The count of the elements to pop from the set.- Returns:
- A set of popped elements will be returned depending on the set's length.
Ifkeydoes not exist, an emptySetwill be returned. - See Also:
- valkey.io for details.
- Example:
Set<GlideString> values1 = client.spopCount(gs("mySet"), 2).get(); assert values1.equals(new GlideString[] {gs("value1"), gs("value2")}); Set<GlideString> values2 = client.spopCount(gs("nonExistingSet"), 2).get(); assert values2.size() == 0;
-
sunion
java.util.concurrent.CompletableFuture<java.util.Set<java.lang.String>> sunion(java.lang.String[] keys)
Gets the union of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- A set of members which are present in at least one of the given sets. If none of the sets exist, an empty set will be returned.
- See Also:
- valkey.io for details.
- Example:
assert client.sadd("my_set1", new String[]{"member1", "member2"}).get() == 2; assert client.sadd("my_set2", new String[]{"member2", "member3"}).get() == 2; Set<String> result = client.sunion(new String[] {"my_set1", "my_set2"}).get(); assertEquals(Set.of("member1", "member2", "member3"), result); result = client.sunion(new String[] {"my_set1", "non_existent_set"}).get(); assertEquals(Set.of("member1", "member2"), result);
-
sunion
java.util.concurrent.CompletableFuture<java.util.Set<GlideString>> sunion(GlideString[] keys)
Gets the union of all the given sets.- Parameters:
keys- The keys of the sets.- Returns:
- A set of members which are present in at least one of the given sets. If none of the sets exist, an empty set will be returned.
- See Also:
- valkey.io for details.
- Example:
assert client.sadd(gs("my_set1"), new GlideString[]{gs("member1"), gs("member2")}).get() == 2; assert client.sadd(gs("my_set2"), new GlideString[]{gs("member2"), gs("member3")}).get() == 2; Set<GlideString> result = client.sunion(new GlideString[] {gs("my_set1"), gs("my_set2")}).get(); assertEquals(Set.of(gs("member1"), gs("member2"), gs("member3")), result); result = client.sunion(new GlideString[] {gs("my_set1"), gs("non_existent_set")}).get(); assertEquals(Set.of(gs("member1"), gs("member2")), result);
-
sscan
java.util.concurrent.CompletableFuture<java.lang.Object[]> sscan(java.lang.String key, java.lang.String cursor)Iterates incrementally over a set.- Parameters:
key- The key of the set.cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the set. The second element is always anArrayof the subset of the set held inkey. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 members String cursor = "0"; Object[] result; do { result = client.sscan(key1, cursor).get(); cursor = result[0].toString(); Object[] stringResults = (Object[]) result[1]; System.out.println("\nSSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); } while (!cursor.equals("0"));
-
sscan
java.util.concurrent.CompletableFuture<java.lang.Object[]> sscan(GlideString key, GlideString cursor)
Iterates incrementally over a set.- Parameters:
key- The key of the set.cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the set. The second element is always anArrayof the subset of the set held inkey. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 members GlideString cursor = gs("0"); Object[] result; do { result = client.sscan(key1, cursor).get(); cursor = gs(result[0].toString()); Object[] glideStringResults = (Object[]) result[1]; System.out.println("\nSSCAN iteration:"); Arrays.asList(glideStringResults).stream().forEach(i -> System.out.print(i + ", ")); } while (!cursor.equals(gs("0")));
-
sscan
java.util.concurrent.CompletableFuture<java.lang.Object[]> sscan(java.lang.String key, java.lang.String cursor, SScanOptions sScanOptions)Iterates incrementally over a set.- Parameters:
key- The key of the set.cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.sScanOptions- TheSScanOptions.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the set. The second element is always anArrayof the subset of the set held inkey. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 members String cursor = "0"; Object[] result; do { result = client.sscan(key1, cursor, SScanOptions.builder().matchPattern("*").count(20L).build()).get(); cursor = result[0].toString(); Object[] stringResults = (Object[]) result[1]; System.out.println("\nSSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); } while (!cursor.equals("0"));
-
sscan
java.util.concurrent.CompletableFuture<java.lang.Object[]> sscan(GlideString key, GlideString cursor, SScanOptionsBinary sScanOptions)
Iterates incrementally over a set.- Parameters:
key- The key of the set.cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.sScanOptions- TheSScanOptions.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the set. The second element is always anArrayof the subset of the set held inkey. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 members GlideString cursor = gs("0"); Object[] result; do { result = client.sscan(key1, cursor, SScanOptionsBinary.builder().matchPattern(gs("*")).count(20L).build()).get(); cursor = gs(result[0].toString()); Object[] glideStringResults = (Object[]) result[1]; System.out.println("\nSSCAN iteration:"); Arrays.asList(glideStringResults).stream().forEach(i -> System.out.print(i + ", ")); } while (!cursor.equals(gs("0")));
-
-