+ add list implementations for Jedis and Jredis
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.Collection;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface RedisCommands extends RedisTxCommands, RedisStringCommands {
|
||||
public interface RedisCommands extends RedisTxCommands, RedisStringCommands, RedisListCommands {
|
||||
|
||||
Boolean exists(String key);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* List-specific commands supported by Redis.
|
||||
*
|
||||
@@ -26,4 +28,26 @@ public interface RedisListCommands {
|
||||
Integer rPush(String key, String value);
|
||||
|
||||
Integer lPush(String key, String value);
|
||||
|
||||
Integer lLen(String key);
|
||||
|
||||
List<String> lRange(String key, int start, int end);
|
||||
|
||||
void lTrim(String key, int start, int end);
|
||||
|
||||
String lIndex(String key, int index);
|
||||
|
||||
void lSet(String key, int index, String value);
|
||||
|
||||
Integer lRem(String key, int count, String value);
|
||||
|
||||
String lPop(String key);
|
||||
|
||||
String rPop(String key);
|
||||
|
||||
List<String> bLPop(int timeout, String... keys);
|
||||
|
||||
List<String> bRPop(int timeout, String... keys);
|
||||
|
||||
String rPopLPush(String srcKey, String dstKey);
|
||||
}
|
||||
|
||||
@@ -326,32 +326,6 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lPush(String key, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lpush(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.lpush(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rPush(String key, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.rpush(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.rpush(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
try {
|
||||
@@ -440,4 +414,170 @@ public class JedisConnection implements RedisConnection {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer lPush(String key, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lpush(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.lpush(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rPush(String key, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.rpush(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.rpush(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> bLPop(int timeout, String... keys) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.blpop(timeout, keys);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> bRPop(int timeout, String... keys) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.brpop(timeout, keys);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lIndex(String key, int index) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lindex(key, index);
|
||||
return null;
|
||||
}
|
||||
return jedis.lindex(key, index);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lLen(String key) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.llen(key);
|
||||
return null;
|
||||
}
|
||||
return jedis.llen(key);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lPop(String key) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lpop(key);
|
||||
return null;
|
||||
}
|
||||
return jedis.lpop(key);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> lRange(String key, int start, int end) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lrange(key, start, end);
|
||||
return null;
|
||||
}
|
||||
return jedis.lrange(key, start, end);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lRem(String key, int count, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lrem(key, count, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.lrem(key, count, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lSet(String key, int index, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.lset(key, index, value);
|
||||
}
|
||||
jedis.lset(key, index, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lTrim(String key, int start, int end) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.ltrim(key, start, end);
|
||||
}
|
||||
jedis.ltrim(key, start, end);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rPop(String key) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.rpop(key);
|
||||
return null;
|
||||
}
|
||||
return jedis.lpop(key);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rPopLPush(String srcKey, String dstKey) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.rpoplpush(srcKey, dstKey);
|
||||
return null;
|
||||
}
|
||||
return jedis.rpoplpush(srcKey, dstKey);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.datastore.redis.connection.jredis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -162,21 +163,6 @@ public class JredisConnection implements RedisConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lPush(String key, String value) {
|
||||
try {
|
||||
jredis.lpush(key, value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rPush(String key, String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
try {
|
||||
@@ -239,4 +225,122 @@ public class JredisConnection implements RedisConnection {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> bLPop(int timeout, String... keys) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> bRPop(int timeout, String... keys) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lIndex(String key, int index) {
|
||||
try {
|
||||
return JredisUtils.convertToString(jredis.lindex(key, (long) index), encoding);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lLen(String key) {
|
||||
try {
|
||||
return Integer.valueOf((int) jredis.llen(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lPop(String key) {
|
||||
try {
|
||||
return JredisUtils.convertToString(jredis.lpop(key), encoding);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lPush(String key, String value) {
|
||||
try {
|
||||
jredis.lpush(key, value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> lRange(String key, int start, int end) {
|
||||
try {
|
||||
List<byte[]> lrange = jredis.lrange(key, start, end);
|
||||
List<String> results = new ArrayList<String>(lrange.size());
|
||||
|
||||
for (byte[] bs : lrange) {
|
||||
results.add(JredisUtils.convertToString(bs, encoding));
|
||||
}
|
||||
return results;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer lRem(String key, int count, String value) {
|
||||
try {
|
||||
Integer.valueOf((int) jredis.lrem(key, value, count));
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lSet(String key, int index, String value) {
|
||||
try {
|
||||
jredis.lset(key, index, value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lTrim(String key, int start, int end) {
|
||||
try {
|
||||
jredis.ltrim(key, start, end);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rPop(String key) {
|
||||
try {
|
||||
return JredisUtils.convertToString(jredis.rpop(key), encoding);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rPopLPush(String srcKey, String dstKey) {
|
||||
try {
|
||||
return JredisUtils.convertToString(jredis.rpoplpush(srcKey, dstKey), encoding);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rPush(String key, String value) {
|
||||
try {
|
||||
jredis.rpush(key, value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user