From b1499b99989bf203f4ec11834136c06950f84a05 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 10 Jan 2011 13:46:40 +0200 Subject: [PATCH] + add support for the new list index command --- .../keyvalue/redis/connection/RedisListCommands.java | 6 ++++++ .../redis/connection/jedis/JedisConnection.java | 12 ++++++++++++ .../keyvalue/redis/connection/jedis/JedisUtils.java | 8 ++++++++ .../redis/connection/jredis/JredisConnection.java | 6 ++++++ 4 files changed, 32 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java index 030040eb9..f2a4f5f82 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java @@ -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); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 60d21faa4..3826c1699 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -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 { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index c6f759b5e..7df52469f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -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); + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 452e64f1b..befd7490a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -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 //