Skip to content
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

Added support for sunion and sinter #147

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
******************************************************************************/
package com.netflix.dyno.jedis;

import com.google.common.collect.Sets;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.dyno.connectionpool.*;
import com.netflix.dyno.connectionpool.exception.DynoConnectException;
Expand All @@ -25,12 +26,13 @@
import com.netflix.dyno.connectionpool.impl.lb.HttpEndpointBasedTokenMapSupplier;
import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils;
import com.netflix.dyno.connectionpool.impl.utils.ZipUtils;
import com.netflix.dyno.contrib.*;

import com.netflix.dyno.contrib.ArchaiusConnectionPoolConfiguration;
import com.netflix.dyno.contrib.DynoCPMonitor;
import com.netflix.dyno.contrib.DynoOPMonitor;
import com.netflix.dyno.contrib.EurekaHostsSupplier;
import org.slf4j.Logger;

import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.*;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.params.geo.GeoRadiusParam;
import redis.clients.jedis.params.sortedset.ZAddParams;
import redis.clients.jedis.params.sortedset.ZIncrByParams;
Expand Down Expand Up @@ -2429,7 +2431,13 @@ public Long msetnx(String... keysvalues) {

@Override
public Set<String> sinter(String... keys) {
throw new UnsupportedOperationException("not yet implemented");
Set<String> allResults = d_smembers(keys[0]).getResult();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign the global set with the first keys smembers.

//loop through keys and intersect to a set, use d_smembers
for(int i = 1; i < keys.length; i++) {
allResults = Sets.intersection(allResults, d_smembers(keys[i]).getResult());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Guava set intersection.

}

return allResults;
}

public Long sinterstore(final String dstkey, final String... keys) {
Expand All @@ -2448,7 +2456,14 @@ public Long sort(String key, String dstkey) {

@Override
public Set<String> sunion(String... keys) {
throw new UnsupportedOperationException("not yet implemented");
Set<String> allResults = new HashSet<String>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just get all the smembers and push it to a single set.

//loop through keys and append to a set, use d_smembers
for(String key : keys) {
OperationResult<Set<String>> results = d_smembers(key);
allResults.addAll(results.getResult());
}

return allResults;
}

@Override
Expand Down