Add Redis 2.6 srandmember with count to Connections

DATAREDIS-116
This commit is contained in:
Jennifer Hickey
2013-06-24 16:15:07 -07:00
parent cc9b0821a0
commit c1337d5067
12 changed files with 153 additions and 0 deletions

View File

@@ -452,6 +452,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.sRandMember(key);
}
public Set<byte[]> sRandMember(byte[] key, long count) {
return delegate.sRandMember(key, count);
}
public Boolean sRem(byte[] key, byte[] value) {
return delegate.sRem(key, value);
}
@@ -1064,6 +1068,9 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return deserialize(delegate.sRandMember(serialize(key)));
}
public Set<String> sRandMember(String key, long count) {
return deserialize(delegate.sRandMember(serialize(key), count));
}
public Boolean sRem(String key, String value) {
return delegate.sRem(serialize(key), serialize(value));

View File

@@ -52,4 +52,6 @@ public interface RedisSetCommands {
Set<byte[]> sMembers(byte[] key);
byte[] sRandMember(byte[] key);
Set<byte[]> sRandMember(byte[] key, long count);
}

View File

@@ -187,6 +187,8 @@ public interface StringRedisConnection extends RedisConnection {
String sRandMember(String key);
Set<String> sRandMember(String key, long count);
Boolean zAdd(String key, double score, String value);
Boolean zRem(String key, String value);

View File

@@ -1691,6 +1691,9 @@ public class JedisConnection implements RedisConnection {
}
}
public Set<byte[]> sRandMember(byte[] key, long count) {
throw new UnsupportedOperationException();
}
public Boolean sRem(byte[] key, byte[] value) {
try {

View File

@@ -883,6 +883,11 @@ public class JredisConnection implements RedisConnection {
}
public Set<byte[]> sRandMember(byte[] key, long count) {
throw new UnsupportedOperationException();
}
public Boolean sRem(byte[] key, byte[] value) {
try {
return jredis.srem(key, value);

View File

@@ -1432,6 +1432,18 @@ public class LettuceConnection implements RedisConnection {
}
}
public Set<byte[]> sRandMember(byte[] key, long count) {
try {
if (isPipelined()) {
pipeline(getAsyncConnection().srandmember(key, count));
return null;
}
return getConnection().srandmember(key, count);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Boolean sRem(byte[] key, byte[] value) {
try {
if (isPipelined()) {

View File

@@ -42,6 +42,7 @@ import redis.Command;
import redis.client.RedisClient;
import redis.client.RedisClient.Pipeline;
import redis.client.RedisException;
import redis.reply.MultiBulkReply;
import redis.reply.Reply;
import com.google.common.base.Charsets;
@@ -1383,6 +1384,17 @@ public class SrpConnection implements RedisConnection {
}
}
public Set<byte[]> sRandMember(byte[] key, long count) {
try {
if (isPipelined()) {
pipeline(pipeline.srandmember(key, count));
return null;
}
return SrpUtils.toSet(((MultiBulkReply)client.srandmember(key, count)).data());
} catch (Exception ex) {
throw convertSrpAccessException(ex);
}
}
public Boolean sRem(byte[] key, byte[] value) {
try {