Merge branch 'DATAREDIS-86'

This commit is contained in:
Costin Leau
2012-05-23 20:45:59 +03:00
9 changed files with 85 additions and 94 deletions

View File

@@ -372,8 +372,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.sDiff(keys);
}
public void sDiffStore(byte[] destKey, byte[]... keys) {
delegate.sDiffStore(destKey, keys);
public Long sDiffStore(byte[] destKey, byte[]... keys) {
return delegate.sDiffStore(destKey, keys);
}
public void select(int dbIndex) {
@@ -412,8 +412,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.sInter(keys);
}
public void sInterStore(byte[] destKey, byte[]... keys) {
delegate.sInterStore(destKey, keys);
public Long sInterStore(byte[] destKey, byte[]... keys) {
return delegate.sInterStore(destKey, keys);
}
public Boolean sIsMember(byte[] key, byte[] value) {
@@ -460,8 +460,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.sUnion(keys);
}
public void sUnionStore(byte[] destKey, byte[]... keys) {
delegate.sUnionStore(destKey, keys);
public Long sUnionStore(byte[] destKey, byte[]... keys) {
return delegate.sUnionStore(destKey, keys);
}
public Long ttl(byte[] key) {

View File

@@ -39,15 +39,15 @@ public interface RedisSetCommands {
Set<byte[]> sInter(byte[]... keys);
void sInterStore(byte[] destKey, byte[]... keys);
Long sInterStore(byte[] destKey, byte[]... keys);
Set<byte[]> sUnion(byte[]... keys);
void sUnionStore(byte[] destKey, byte[]... keys);
Long sUnionStore(byte[] destKey, byte[]... keys);
Set<byte[]> sDiff(byte[]... keys);
void sDiffStore(byte[] destKey, byte[]... keys);
Long sDiffStore(byte[] destKey, byte[]... keys);
Set<byte[]> sMembers(byte[] key);

View File

@@ -1423,17 +1423,17 @@ public class JedisConnection implements RedisConnection {
}
public void sDiffStore(byte[] destKey, byte[]... keys) {
public Long sDiffStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sdiffstore(destKey, keys);
return;
return null;
}
if (isPipelined()) {
pipeline.sdiffstore(destKey, keys);
return;
return null;
}
jedis.sdiffstore(destKey, keys);
return jedis.sdiffstore(destKey, keys);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -1457,17 +1457,17 @@ public class JedisConnection implements RedisConnection {
}
public void sInterStore(byte[] destKey, byte[]... keys) {
public Long sInterStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sinterstore(destKey, keys);
return;
return null;
}
if (isPipelined()) {
pipeline.sinterstore(destKey, keys);
return;
return null;
}
jedis.sinterstore(destKey, keys);
return jedis.sinterstore(destKey, keys);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -1593,17 +1593,17 @@ public class JedisConnection implements RedisConnection {
}
public void sUnionStore(byte[] destKey, byte[]... keys) {
public Long sUnionStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sunionstore(destKey, keys);
return;
return null;
}
if (isPipelined()) {
pipeline.sunionstore(destKey, keys);
return;
return null;
}
jedis.sunionstore(destKey, keys);
return jedis.sunionstore(destKey, keys);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}

View File

@@ -710,12 +710,13 @@ public class JredisConnection implements RedisConnection {
}
public void sDiffStore(byte[] destKey, byte[]... keys) {
public Long sDiffStore(byte[] destKey, byte[]... keys) {
String destSet = JredisUtils.decode(destKey);
String[] sets = JredisUtils.decodeMultiple(keys);
try {
jredis.sdiffstore(destSet, sets);
return Long.valueOf(-1);
} catch (Exception ex) {
throw convertJredisAccessException(ex);
}
@@ -735,12 +736,13 @@ public class JredisConnection implements RedisConnection {
}
public void sInterStore(byte[] destKey, byte[]... keys) {
public Long sInterStore(byte[] destKey, byte[]... keys) {
String destSet = JredisUtils.decode(destKey);
String[] sets = JredisUtils.decodeMultiple(keys);
try {
jredis.sinterstore(destSet, sets);
return Long.valueOf(-1);
} catch (Exception ex) {
throw convertJredisAccessException(ex);
}
@@ -813,12 +815,13 @@ public class JredisConnection implements RedisConnection {
}
public void sUnionStore(byte[] destKey, byte[]... keys) {
public Long sUnionStore(byte[] destKey, byte[]... keys) {
String destSet = JredisUtils.decode(destKey);
String[] sets = JredisUtils.decodeMultiple(keys);
try {
jredis.sunionstore(destSet, sets);
return Long.valueOf(-1);
} catch (Exception ex) {
throw convertJredisAccessException(ex);
}

View File

@@ -1254,7 +1254,7 @@ public class RjcConnection implements RedisConnection {
}
public void sDiffStore(byte[] destKey, byte[]... keys) {
public Long sDiffStore(byte[] destKey, byte[]... keys) {
String stringKey = RjcUtils.decode(destKey);
String[] stringKeys = RjcUtils.decodeMultiple(keys);
@@ -1262,9 +1262,9 @@ public class RjcConnection implements RedisConnection {
if (isPipelined()) {
pipeline.sdiffstore(stringKey, stringKeys);
return;
return null;
}
session.sdiffstore(stringKey, stringKeys);
return session.sdiffstore(stringKey, stringKeys);
} catch (Exception ex) {
throw convertRjcAccessException(ex);
}
@@ -1286,16 +1286,16 @@ public class RjcConnection implements RedisConnection {
}
public void sInterStore(byte[] destKey, byte[]... keys) {
public Long sInterStore(byte[] destKey, byte[]... keys) {
String stringKey = RjcUtils.decode(destKey);
String[] stringKeys = RjcUtils.decodeMultiple(keys);
try {
if (isPipelined()) {
pipeline.sinterstore(stringKey, stringKeys);
return;
return null;
}
session.sinterstore(stringKey, stringKeys);
return session.sinterstore(stringKey, stringKeys);
} catch (Exception ex) {
throw convertRjcAccessException(ex);
}
@@ -1415,7 +1415,7 @@ public class RjcConnection implements RedisConnection {
}
public void sUnionStore(byte[] destKey, byte[]... keys) {
public Long sUnionStore(byte[] destKey, byte[]... keys) {
String stringKey = RjcUtils.decode(destKey);
String[] stringKeys = RjcUtils.decodeMultiple(keys);
@@ -1423,9 +1423,9 @@ public class RjcConnection implements RedisConnection {
if (isPipelined()) {
pipeline.sunionstore(stringKey, stringKeys);
return;
return null;
}
session.sunionstore(stringKey, stringKeys);
return session.sunionstore(stringKey, stringKeys);
} catch (Exception ex) {
throw convertRjcAccessException(ex);
}

View File

@@ -49,8 +49,6 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
return difference(key, Collections.singleton(otherKey));
}
@SuppressWarnings("unchecked")
public Set<V> difference(final K key, final Collection<K> otherKeys) {
final byte[][] rawKeys = rawKeys(key, otherKeys);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
@@ -64,19 +62,18 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
}
public void differenceAndStore(K key, K otherKey, K destKey) {
differenceAndStore(key, Collections.singleton(otherKey), destKey);
public Long differenceAndStore(K key, K otherKey, K 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[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.sDiffStore(rawDestKey, rawKeys);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.sDiffStore(rawDestKey, rawKeys);
}
}, true);
}
@@ -86,8 +83,6 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
return intersect(key, Collections.singleton(otherKey));
}
@SuppressWarnings("unchecked")
public Set<V> intersect(K key, Collection<K> otherKeys) {
final byte[][] rawKeys = rawKeys(key, otherKeys);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
@@ -101,17 +96,17 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
}
public void intersectAndStore(K key, K otherKey, K destKey) {
intersectAndStore(key, Collections.singleton(otherKey), destKey);
public Long intersectAndStore(K key, K otherKey, K 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[] 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);
return null;
}
@@ -130,8 +125,6 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
}, true);
}
@SuppressWarnings("unchecked")
public Set<V> members(K key) {
final byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
@@ -222,19 +215,18 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
}
public void unionAndStore(K key, K otherKey, K destKey) {
unionAndStore(key, Collections.singleton(otherKey), destKey);
public Long unionAndStore(K key, K otherKey, K 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[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.sUnionStore(rawDestKey, rawKeys);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.sUnionStore(rawDestKey, rawKeys);
}
}, true);
}

View File

@@ -60,19 +60,18 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
public void intersectAndStore(K key, K otherKey, K destKey) {
intersectAndStore(key, Collections.singleton(otherKey), destKey);
public Long intersectAndStore(K key, K otherKey, K 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[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.zInterStore(rawDestKey, rawKeys);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.zInterStore(rawDestKey, rawKeys);
}
}, true);
}
@@ -233,25 +232,23 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
public void removeRange(K key, final long start, final long end) {
public Long removeRange(K key, final long start, final long end) {
final byte[] rawKey = rawKey(key);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.zRemRange(rawKey, start, end);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.zRemRange(rawKey, start, end);
}
}, true);
}
public void removeRangeByScore(K key, final double min, final double max) {
public Long removeRangeByScore(K key, final double min, final double max) {
final byte[] rawKey = rawKey(key);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.zRemRangeByScore(rawKey, min, max);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.zRemRangeByScore(rawKey, min, max);
}
}, true);
}
@@ -294,19 +291,18 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
public void unionAndStore(K key, K otherKey, K destKey) {
unionAndStore(key, Collections.singleton(otherKey), destKey);
public Long unionAndStore(K key, K otherKey, K 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[] rawDestKey = rawKey(destKey);
execute(new RedisCallback<Object>() {
return execute(new RedisCallback<Long>() {
public Object doInRedis(RedisConnection connection) {
connection.zUnionStore(rawDestKey, rawKeys);
return null;
public Long doInRedis(RedisConnection connection) {
return connection.zUnionStore(rawDestKey, rawKeys);
}
}, true);
}

View File

@@ -30,25 +30,25 @@ public interface SetOperations<K, V> {
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, 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, 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);

View File

@@ -35,13 +35,13 @@ public interface ZSetOperations<K, V> {
Double getScore();
}
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);
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);
Set<V> range(K key, long start, long end);
@@ -71,9 +71,9 @@ public interface ZSetOperations<K, V> {
Boolean remove(K key, Object o);
void removeRange(K key, long start, long end);
Long removeRange(K key, long start, long end);
void removeRangeByScore(K key, double min, double max);
Long removeRangeByScore(K key, double min, double max);
Long count(K key, double min, double max);