+ add support for the new list index command

This commit is contained in:
Costin Leau
2011-01-10 13:46:40 +02:00
parent 1966409375
commit b1499b9998
4 changed files with 32 additions and 0 deletions

View File

@@ -25,6 +25,10 @@ import java.util.List;
*/
public interface RedisListCommands {
public enum POSITION {
BEFORE, AFTER
}
Long rPush(byte[] key, byte[] value);
Long lPush(byte[] key, byte[] value);
@@ -37,6 +41,8 @@ public interface RedisListCommands {
byte[] lIndex(byte[] key, long index);
Long lInsert(byte[] key, POSITION where, byte[] pivot, byte[] value);
void lSet(byte[] key, long index, byte[] value);
Long lRem(byte[] key, long count, byte[] value);

View File

@@ -671,6 +671,18 @@ public class JedisConnection implements RedisConnection {
}
}
@Override
public Long lInsert(byte[] key, POSITION where, byte[] pivot, byte[] value) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
return jedis.linsert(key, JedisUtils.convertPosition(where), pivot, value);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
public Long lLen(byte[] key) {
try {

View File

@@ -30,12 +30,15 @@ import org.springframework.data.keyvalue.redis.RedisConnectionFailureException;
import org.springframework.data.keyvalue.redis.UncategorizedRedisException;
import org.springframework.data.keyvalue.redis.connection.DefaultTuple;
import org.springframework.data.keyvalue.redis.connection.SortParameters;
import org.springframework.data.keyvalue.redis.connection.RedisListCommands.POSITION;
import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
import org.springframework.util.Assert;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
/**
* Helper class featuring methods for Jedis connection handling, providing support for exception translation.
@@ -169,4 +172,9 @@ public abstract class JedisUtils {
static byte[] asBit(boolean value) {
return (value ? ONE : ZERO);
}
static LIST_POSITION convertPosition(POSITION where) {
Assert.notNull("list positions are mandatory");
return (POSITION.AFTER.equals(where) ? LIST_POSITION.AFTER : LIST_POSITION.BEFORE);
}
}

View File

@@ -511,6 +511,12 @@ public class JredisConnection implements RedisConnection {
}
}
@Override
public Long lInsert(byte[] key, POSITION where, byte[] pivot, byte[] value) {
throw new UnsupportedOperationException();
}
//
// Set commands
//