Skip to content

Commit

Permalink
Make Template Set *storeOps() return the resulting set size
Browse files Browse the repository at this point in the history
  • Loading branch information
Costin Leau committed May 23, 2012
1 parent 646f1e3 commit 042f3e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
Expand Up @@ -49,8 +49,6 @@ public Set<V> difference(K key, K otherKey) {
return difference(key, Collections.singleton(otherKey)); return difference(key, Collections.singleton(otherKey));
} }


@SuppressWarnings("unchecked")

public Set<V> difference(final K key, final Collection<K> otherKeys) { public Set<V> difference(final K key, final Collection<K> otherKeys) {
final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[][] rawKeys = rawKeys(key, otherKeys);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
Expand All @@ -64,19 +62,18 @@ public Set<byte[]> doInRedis(RedisConnection connection) {
} }




public void differenceAndStore(K key, K otherKey, K destKey) { public Long differenceAndStore(K key, K otherKey, K destKey) {
differenceAndStore(key, Collections.singleton(otherKey), destKey); return differenceAndStore(key, Collections.singleton(otherKey), destKey);
} }




public void differenceAndStore(final K key, final Collection<K> otherKeys, K destKey) { public Long differenceAndStore(final K key, final Collection<K> otherKeys, K destKey) {
final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[][] rawKeys = rawKeys(key, otherKeys);
final byte[] rawDestKey = rawKey(destKey); final byte[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() { return execute(new RedisCallback<Long>() {


public Object doInRedis(RedisConnection connection) { public Long doInRedis(RedisConnection connection) {
connection.sDiffStore(rawDestKey, rawKeys); return connection.sDiffStore(rawDestKey, rawKeys);
return null;
} }
}, true); }, true);
} }
Expand All @@ -86,8 +83,6 @@ public Set<V> intersect(K key, K otherKey) {
return intersect(key, Collections.singleton(otherKey)); return intersect(key, Collections.singleton(otherKey));
} }


@SuppressWarnings("unchecked")

public Set<V> intersect(K key, Collection<K> otherKeys) { public Set<V> intersect(K key, Collection<K> otherKeys) {
final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[][] rawKeys = rawKeys(key, otherKeys);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
Expand All @@ -101,17 +96,17 @@ public Set<byte[]> doInRedis(RedisConnection connection) {
} }




public void intersectAndStore(K key, K otherKey, K destKey) { public Long intersectAndStore(K key, K otherKey, K destKey) {
intersectAndStore(key, Collections.singleton(otherKey), destKey); return intersectAndStore(key, Collections.singleton(otherKey), destKey);
} }




public void intersectAndStore(K key, Collection<K> otherKeys, K destKey) { public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[][] rawKeys = rawKeys(key, otherKeys);
final byte[] rawDestKey = rawKey(destKey); final byte[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() { return execute(new RedisCallback<Long>() {


public Object doInRedis(RedisConnection connection) { public Long doInRedis(RedisConnection connection) {
connection.sInterStore(rawDestKey, rawKeys); connection.sInterStore(rawDestKey, rawKeys);
return null; return null;
} }
Expand All @@ -130,8 +125,6 @@ public Boolean doInRedis(RedisConnection connection) {
}, true); }, true);
} }


@SuppressWarnings("unchecked")

public Set<V> members(K key) { public Set<V> members(K key) {
final byte[] rawKey = rawKey(key); final byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
Expand Down Expand Up @@ -222,19 +215,18 @@ public Set<byte[]> doInRedis(RedisConnection connection) {
} }




public void unionAndStore(K key, K otherKey, K destKey) { public Long unionAndStore(K key, K otherKey, K destKey) {
unionAndStore(key, Collections.singleton(otherKey), destKey); return unionAndStore(key, Collections.singleton(otherKey), destKey);
} }




public void unionAndStore(K key, Collection<K> otherKeys, K destKey) { public Long unionAndStore(K key, Collection<K> otherKeys, K destKey) {
final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[][] rawKeys = rawKeys(key, otherKeys);
final byte[] rawDestKey = rawKey(destKey); final byte[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() { return execute(new RedisCallback<Long>() {


public Object doInRedis(RedisConnection connection) { public Long doInRedis(RedisConnection connection) {
connection.sUnionStore(rawDestKey, rawKeys); return connection.sUnionStore(rawDestKey, rawKeys);
return null;
} }
}, true); }, true);
} }
Expand Down
Expand Up @@ -30,25 +30,25 @@ public interface SetOperations<K, V> {


Set<V> difference(K key, Collection<K> otherKeys); Set<V> difference(K key, Collection<K> otherKeys);


void differenceAndStore(K key, K otherKey, K destKey); Long differenceAndStore(K key, K otherKey, K destKey);


void differenceAndStore(K key, Collection<K> otherKeys, K destKey); Long differenceAndStore(K key, Collection<K> otherKeys, K destKey);


Set<V> intersect(K key, K otherKey); Set<V> intersect(K key, K otherKey);


Set<V> intersect(K key, Collection<K> otherKeys); Set<V> intersect(K key, Collection<K> otherKeys);


void intersectAndStore(K key, K otherKey, K destKey); Long intersectAndStore(K key, K otherKey, K destKey);


void intersectAndStore(K key, Collection<K> otherKeys, K destKey); Long intersectAndStore(K key, Collection<K> otherKeys, K destKey);


Set<V> union(K key, K otherKey); Set<V> union(K key, K otherKey);


Set<V> union(K key, Collection<K> otherKeys); Set<V> union(K key, Collection<K> otherKeys);


void unionAndStore(K key, K otherKey, K destKey); Long unionAndStore(K key, K otherKey, K destKey);


void unionAndStore(K key, Collection<K> otherKeys, K destKey); Long unionAndStore(K key, Collection<K> otherKeys, K destKey);


Boolean add(K key, V value); Boolean add(K key, V value);


Expand Down

0 comments on commit 042f3e8

Please sign in to comment.