diff --git a/spring-datastore-redis/pom.xml b/spring-datastore-redis/pom.xml
index 95b738e3c..45683d3a6 100644
--- a/spring-datastore-redis/pom.xml
+++ b/spring-datastore-redis/pom.xml
@@ -13,6 +13,7 @@
02112010
+ 1.4.0
@@ -96,7 +97,7 @@
redis.clients
jedis
- 1.3.1
+ ${jedis.ver}
compile
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultTuple.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultTuple.java
index 62807b8d2..11d8d68e4 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultTuple.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultTuple.java
@@ -25,7 +25,7 @@ import org.springframework.datastore.redis.connection.RedisZSetCommands.Tuple;
public class DefaultTuple implements Tuple {
private final Double score;
- private final String value;
+ private final byte[] value;
/**
@@ -34,7 +34,7 @@ public class DefaultTuple implements Tuple {
* @param value
* @param score
*/
- public DefaultTuple(String value, Double score) {
+ public DefaultTuple(byte[] value, Double score) {
this.score = score;
this.value = value;
}
@@ -45,7 +45,7 @@ public class DefaultTuple implements Tuple {
}
@Override
- public String getValue() {
+ public byte[] getValue() {
return value;
}
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java
index 74d284309..70e1cd397 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java
@@ -26,27 +26,27 @@ import java.util.Collection;
public interface RedisCommands extends RedisTxCommands, RedisStringCommands, RedisListCommands, RedisSetCommands,
RedisZSetCommands, RedisHashCommands {
- Boolean exists(String key);
+ Boolean exists(byte[] key);
- Integer del(String... keys);
+ Integer del(byte[]... keys);
- DataType type(String key);
+ DataType type(byte[] key);
- Collection keys(String pattern);
+ Collection keys(byte[] pattern);
- String randomKey();
+ byte[] randomKey();
- void rename(String oldName, String newName);
+ void rename(byte[] oldName, byte[] newName);
- Boolean renameNX(String oldName, String newName);
+ Boolean renameNX(byte[] oldName, byte[] newName);
Integer dbSize();
- Boolean expire(String key, int seconds);
+ Boolean expire(byte[] key, int seconds);
- Boolean persist(String key);
+ Boolean persist(byte[] key);
- Integer ttl(String key);
+ Integer ttl(byte[] key);
void select(int dbIndex);
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisConnection.java
index ce94a9911..46de8ffd7 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisConnection.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisConnection.java
@@ -37,8 +37,6 @@ public interface RedisConnection extends RedisCommands {
Object getNativeConnection();
- String getEncoding();
-
/**
* Indicates whether the connection is in "queue"(or "MULTI") mode or not.
* When queueing, all commands are postponed until EXEC or DISCARD commands
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisHashCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisHashCommands.java
index e51cf5ddd..aac379edb 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisHashCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisHashCommands.java
@@ -17,6 +17,7 @@
package org.springframework.datastore.redis.connection;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -26,33 +27,27 @@ import java.util.Set;
*/
public interface RedisHashCommands {
- public interface Entry {
- public String getField();
+ Boolean hSet(byte[] key, byte[] field, byte[] value);
- public String getValue();
- }
+ Boolean hSetNX(byte[] key, byte[] field, byte[] value);
- Boolean hSet(String key, String field, String value);
+ byte[] hGet(byte[] key, byte[] field);
- Boolean hSetNX(String key, String field, String value);
+ List hMGet(byte[] key, byte[]... fields);
- String hGet(String key, String field);
+ void hMSet(byte[] key, Map hashes);
- List hMGet(String key, String... fields);
+ Integer hIncrBy(byte[] key, byte[] field, int delta);
- void hMSet(String key, String[] fields, String[] values);
+ Boolean hExists(byte[] key, byte[] field);
- Integer hIncrBy(String key, String field, int delta);
+ Boolean hDel(byte[] key, byte[] field);
- Boolean hExists(String key, String field);
+ Integer hLen(byte[] key);
- Boolean hDel(String key, String field);
+ Set hKeys(byte[] key);
- Integer hLen(String key);
+ List hVals(byte[] key);
- Set hKeys(String key);
-
- List hVals(String key);
-
- Set hGetAll(String key);
+ Map hGetAll(byte[] key);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisListCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisListCommands.java
index bb2730005..0fdc343bf 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisListCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisListCommands.java
@@ -25,29 +25,29 @@ import java.util.List;
*/
public interface RedisListCommands {
- Integer rPush(String key, String value);
+ Integer rPush(byte[] key, byte[] value);
- Integer lPush(String key, String value);
+ Integer lPush(byte[] key, byte[] value);
- Integer lLen(String key);
+ Integer lLen(byte[] key);
- List lRange(String key, int start, int end);
+ List lRange(byte[] key, int start, int end);
- void lTrim(String key, int start, int end);
+ void lTrim(byte[] key, int start, int end);
- String lIndex(String key, int index);
+ byte[] lIndex(byte[] key, int index);
- void lSet(String key, int index, String value);
+ void lSet(byte[] key, int index, byte[] value);
- Integer lRem(String key, int count, String value);
+ Integer lRem(byte[] key, int count, byte[] value);
- String lPop(String key);
+ byte[] lPop(byte[] key);
- String rPop(String key);
+ byte[] rPop(byte[] key);
- List bLPop(int timeout, String... keys);
+ List bLPop(int timeout, byte[]... keys);
- List bRPop(int timeout, String... keys);
+ List bRPop(int timeout, byte[]... keys);
- String rPopLPush(String srcKey, String dstKey);
+ byte[] rPopLPush(byte[] srcKey, byte[] dstKey);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisSetCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisSetCommands.java
index 302710d1e..244d0f3d8 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisSetCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisSetCommands.java
@@ -25,31 +25,31 @@ import java.util.Set;
*/
public interface RedisSetCommands {
- Boolean sAdd(String key, String value);
+ Boolean sAdd(byte[] key, byte[] value);
- Boolean sRem(String key, String value);
+ Boolean sRem(byte[] key, byte[] value);
- String sPop(String key);
+ byte[] sPop(byte[] key);
- Boolean sMove(String srcKey, String destKey, String value);
+ Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value);
- Integer sCard(String key);
+ Integer sCard(byte[] key);
- Boolean sIsMember(String key, String value);
+ Boolean sIsMember(byte[] key, byte[] value);
- Set sInter(String... keys);
+ Set sInter(byte[]... keys);
- void sInterStore(String destKey, String... keys);
+ void sInterStore(byte[] destKey, byte[]... keys);
- Set sUnion(String... keys);
+ Set sUnion(byte[]... keys);
- void sUnionStore(String destKey, String... keys);
+ void sUnionStore(byte[] destKey, byte[]... keys);
- Set sDiff(String... keys);
+ Set sDiff(byte[]... keys);
- void sDiffStore(String destKey, String... keys);
+ void sDiffStore(byte[] destKey, byte[]... keys);
- Set sMembers(String key);
+ Set sMembers(byte[] key);
- String sRandMember(String key);
+ byte[] sRandMember(byte[] key);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisStringCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisStringCommands.java
index 2f163d3e5..b5c56f1a2 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisStringCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisStringCommands.java
@@ -17,6 +17,7 @@
package org.springframework.datastore.redis.connection;
import java.util.List;
+import java.util.Map;
/**
* String specific commands supported by Redis.
@@ -25,31 +26,31 @@ import java.util.List;
*/
public interface RedisStringCommands {
- void set(String key, String value);
+ void set(byte[] key, byte[] value);
- String get(String key);
+ byte[] get(byte[] key);
- String getSet(String key, String value);
+ byte[] getSet(byte[] key, byte[] value);
- List mGet(String... keys);
+ List mGet(byte[]... keys);
- Boolean setNX(String key, String value);
+ Boolean setNX(byte[] key, byte[] value);
- void setEx(String key, int seconds, String value);
+ void setEx(byte[] key, int seconds, byte[] value);
- void mSet(String[] keys, String[] values);
+ void mSet(Map tuple);
- void mSetNX(String[] keys, String[] values);
+ void mSetNX(Map tuple);
- Integer incr(String key);
+ Integer incr(byte[] key);
- Integer incrBy(String key, int value);
+ Integer incrBy(byte[] key, int value);
- Integer decr(String key);
+ Integer decr(byte[] key);
- Integer decrBy(String key, int value);
+ Integer decrBy(byte[] key, int value);
- Integer append(String key, String value);
+ Integer append(byte[] key, byte[] value);
- String substr(String key, int start, int end);
+ byte[] substr(byte[] key, int start, int end);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisTxCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisTxCommands.java
index 23ee193ae..db2592817 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisTxCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisTxCommands.java
@@ -31,7 +31,7 @@ public interface RedisTxCommands {
void discard();
- void watch(String... keys);
+ void watch(byte[]... keys);
void unwatch();
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisZSetCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisZSetCommands.java
index 1024c3169..93a11200d 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisZSetCommands.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisZSetCommands.java
@@ -31,52 +31,52 @@ public interface RedisZSetCommands {
}
public interface Tuple {
- String getValue();
+ byte[] getValue();
Double getScore();
}
- Boolean zAdd(String key, double score, String value);
+ Boolean zAdd(byte[] key, double score, byte[] value);
- Boolean zRem(String key, String value);
+ Boolean zRem(byte[] key, byte[] value);
- Double zIncrBy(String key, double increment, String value);
+ Double zIncrBy(byte[] key, double increment, byte[] value);
- Integer zRank(String key, String value);
+ Integer zRank(byte[] key, byte[] value);
- Integer zRevRank(String key, String value);
+ Integer zRevRank(byte[] key, byte[] value);
- Set zRange(String key, int start, int end);
+ Set zRange(byte[] key, int start, int end);
- Set zRangeWithScore(String key, int start, int end);
+ Set zRangeWithScore(byte[] key, int start, int end);
- Set zRevRange(String key, int start, int end);
+ Set zRevRange(byte[] key, int start, int end);
- Set zRevRangeWithScore(String key, int start, int end);
+ Set zRevRangeWithScore(byte[] key, int start, int end);
- Set zRangeByScore(String key, double min, double max);
+ Set zRangeByScore(byte[] key, double min, double max);
- Set zRangeByScoreWithScore(String key, double min, double max);
+ Set zRangeByScoreWithScore(byte[] key, double min, double max);
- Set zRangeByScore(String key, double min, double max, int offset, int count);
+ Set zRangeByScore(byte[] key, double min, double max, int offset, int count);
- Set zRangeByScoreWithScore(String key, double min, double max, int offset, int count);
+ Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count);
- Integer zCount(String key, double min, double max);
+ Integer zCount(byte[] key, double min, double max);
- Integer zCard(String key);
+ Integer zCard(byte[] key);
- Double zScore(String key, String value);
+ Double zScore(byte[] key, byte[] value);
- Integer zRemRange(String key, int start, int end);
+ Integer zRemRange(byte[] key, int start, int end);
- Integer zRemRangeByScore(String key, double min, double max);
+ Integer zRemRangeByScore(byte[] key, double min, double max);
- Integer zUnionStore(String destKey, String... sets);
+ Integer zUnionStore(byte[] destKey, byte[]... sets);
- Integer zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
+ Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets);
- Integer zInterStore(String destKey, String... sets);
+ Integer zInterStore(byte[] destKey, byte[]... sets);
- Integer zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
+ Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets);
}
\ No newline at end of file
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java
index 075e15542..6a3c7c53e 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java
@@ -17,8 +17,8 @@ package org.springframework.datastore.redis.connection.jedis;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -30,6 +30,8 @@ import org.springframework.datastore.redis.connection.DataType;
import org.springframework.datastore.redis.connection.RedisConnection;
import org.springframework.util.ReflectionUtils;
+import redis.clients.jedis.BinaryJedis;
+import redis.clients.jedis.BinaryTransaction;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
@@ -46,13 +48,13 @@ public class JedisConnection implements RedisConnection {
private static final Field CLIENT_FIELD;
static {
- CLIENT_FIELD = ReflectionUtils.findField(Jedis.class, "client", Client.class);
+ CLIENT_FIELD = ReflectionUtils.findField(BinaryJedis.class, "client", Client.class);
ReflectionUtils.makeAccessible(CLIENT_FIELD);
}
private final Jedis jedis;
private final Client client;
- private final Transaction transaction;
+ private final BinaryTransaction transaction;
public JedisConnection(Jedis jedis) {
this.jedis = jedis;
@@ -86,11 +88,6 @@ public class JedisConnection implements RedisConnection {
}
}
- @Override
- public String getEncoding() {
- return "UTF-8";
- }
-
@Override
public Jedis getNativeConnection() {
return jedis;
@@ -124,7 +121,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer del(String... keys) {
+ public Integer del(byte[]... keys) {
try {
if (isQueueing()) {
transaction.del(keys);
@@ -155,7 +152,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean exists(String key) {
+ public Boolean exists(byte[] key) {
try {
if (isQueueing()) {
transaction.exists(key);
@@ -168,7 +165,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean expire(String key, int seconds) {
+ public Boolean expire(byte[] key, int seconds) {
try {
if (isQueueing()) {
transaction.expire(key, seconds);
@@ -181,7 +178,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Collection keys(String pattern) {
+ public Collection keys(byte[] pattern) {
try {
if (isQueueing()) {
transaction.keys(pattern);
@@ -203,7 +200,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean persist(String key) {
+ public Boolean persist(byte[] key) {
try {
if (isQueueing()) {
client.persist(key);
@@ -216,20 +213,20 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String randomKey() {
+ public byte[] randomKey() {
try {
if (isQueueing()) {
- transaction.randomKey();
+ transaction.randomBinaryKey();
return null;
}
- return jedis.randomKey();
+ return jedis.randomBinaryKey();
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public void rename(String oldName, String newName) {
+ public void rename(byte[] oldName, byte[] newName) {
try {
if (isQueueing()) {
transaction.rename(oldName, newName);
@@ -241,7 +238,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean renameNX(String oldName, String newName) {
+ public Boolean renameNX(byte[] oldName, byte[] newName) {
try {
if (isQueueing()) {
transaction.renamenx(oldName, newName);
@@ -266,7 +263,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer ttl(String key) {
+ public Integer ttl(byte[] key) {
try {
if (isQueueing()) {
transaction.ttl(key);
@@ -279,7 +276,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public DataType type(String key) {
+ public DataType type(byte[] key) {
try {
if (isQueueing()) {
transaction.type(key);
@@ -301,14 +298,14 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void watch(String... keys) {
+ public void watch(byte[]... keys) {
if (isQueueing()) {
// ignore (as watch not allowed in multi)
return;
}
try {
- for (String key : keys) {
+ for (byte[] key : keys) {
jedis.watch(key);
}
} catch (Exception ex) {
@@ -321,7 +318,7 @@ public class JedisConnection implements RedisConnection {
//
@Override
- public String get(String key) {
+ public byte[] get(byte[] key) {
try {
if (isQueueing()) {
transaction.get(key);
@@ -335,7 +332,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void set(String key, String value) {
+ public void set(byte[] key, byte[] value) {
try {
jedis.set(key, value);
} catch (Exception ex) {
@@ -345,7 +342,7 @@ public class JedisConnection implements RedisConnection {
@Override
- public String getSet(String key, String value) {
+ public byte[] getSet(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.getSet(key, value);
@@ -358,7 +355,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer append(String key, String value) {
+ public Integer append(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.append(key, value);
@@ -371,7 +368,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public List mGet(String... keys) {
+ public List mGet(byte[]... keys) {
try {
if (isQueueing()) {
transaction.mget(keys);
@@ -384,31 +381,31 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void mSet(String[] keys, String[] values) {
+ public void mSet(Map tuples) {
try {
if (isQueueing()) {
- transaction.mset(JedisUtils.arrange(keys, values));
+ transaction.mset(JedisUtils.convert(tuples));
}
- jedis.mset(JedisUtils.arrange(keys, values));
+ jedis.mset(JedisUtils.convert(tuples));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public void mSetNX(String[] keys, String[] values) {
+ public void mSetNX(Map tuples) {
try {
if (isQueueing()) {
- transaction.msetnx(JedisUtils.arrange(keys, values));
+ transaction.msetnx(JedisUtils.convert(tuples));
}
- jedis.msetnx(JedisUtils.arrange(keys, values));
+ jedis.msetnx(JedisUtils.convert(tuples));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public void setEx(String key, int time, String value) {
+ public void setEx(byte[] key, int time, byte[] value) {
try {
if (isQueueing()) {
transaction.setex(key, time, value);
@@ -420,7 +417,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean setNX(String key, String value) {
+ public Boolean setNX(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.setnx(key, value);
@@ -432,7 +429,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String substr(String key, int start, int end) {
+ public byte[] substr(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.substr(key, start, end);
@@ -445,7 +442,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer decr(String key) {
+ public Integer decr(byte[] key) {
try {
if (isQueueing()) {
transaction.decr(key);
@@ -458,7 +455,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer decrBy(String key, int value) {
+ public Integer decrBy(byte[] key, int value) {
try {
if (isQueueing()) {
transaction.decrBy(key, value);
@@ -471,7 +468,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer incr(String key) {
+ public Integer incr(byte[] key) {
try {
if (isQueueing()) {
transaction.incr(key);
@@ -484,7 +481,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer incrBy(String key, int value) {
+ public Integer incrBy(byte[] key, int value) {
try {
if (isQueueing()) {
transaction.incrBy(key, value);
@@ -502,7 +499,7 @@ public class JedisConnection implements RedisConnection {
@Override
- public Integer lPush(String key, String value) {
+ public Integer lPush(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.lpush(key, value);
@@ -515,7 +512,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer rPush(String key, String value) {
+ public Integer rPush(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.rpush(key, value);
@@ -528,7 +525,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public List bLPop(int timeout, String... keys) {
+ public List bLPop(int timeout, byte[]... keys) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -540,7 +537,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public List bRPop(int timeout, String... keys) {
+ public List bRPop(int timeout, byte[]... keys) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -552,7 +549,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String lIndex(String key, int index) {
+ public byte[] lIndex(byte[] key, int index) {
try {
if (isQueueing()) {
transaction.lindex(key, index);
@@ -565,7 +562,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer lLen(String key) {
+ public Integer lLen(byte[] key) {
try {
if (isQueueing()) {
transaction.llen(key);
@@ -578,7 +575,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String lPop(String key) {
+ public byte[] lPop(byte[] key) {
try {
if (isQueueing()) {
transaction.lpop(key);
@@ -591,7 +588,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public List lRange(String key, int start, int end) {
+ public List lRange(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.lrange(key, start, end);
@@ -604,7 +601,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer lRem(String key, int count, String value) {
+ public Integer lRem(byte[] key, int count, byte[] value) {
try {
if (isQueueing()) {
transaction.lrem(key, count, value);
@@ -617,7 +614,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void lSet(String key, int index, String value) {
+ public void lSet(byte[] key, int index, byte[] value) {
try {
if (isQueueing()) {
transaction.lset(key, index, value);
@@ -629,7 +626,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void lTrim(String key, int start, int end) {
+ public void lTrim(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.ltrim(key, start, end);
@@ -641,7 +638,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String rPop(String key) {
+ public byte[] rPop(byte[] key) {
try {
if (isQueueing()) {
transaction.rpop(key);
@@ -654,7 +651,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String rPopLPush(String srcKey, String dstKey) {
+ public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
try {
if (isQueueing()) {
transaction.rpoplpush(srcKey, dstKey);
@@ -672,7 +669,7 @@ public class JedisConnection implements RedisConnection {
//
@Override
- public Boolean sAdd(String key, String value) {
+ public Boolean sAdd(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.sadd(key, value);
@@ -685,7 +682,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer sCard(String key) {
+ public Integer sCard(byte[] key) {
try {
if (isQueueing()) {
transaction.scard(key);
@@ -698,7 +695,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set sDiff(String... keys) {
+ public Set sDiff(byte[]... keys) {
try {
if (isQueueing()) {
transaction.sdiff(keys);
@@ -711,7 +708,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void sDiffStore(String destKey, String... keys) {
+ public void sDiffStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sdiffstore(destKey, keys);
@@ -723,7 +720,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set sInter(String... keys) {
+ public Set sInter(byte[]... keys) {
try {
if (isQueueing()) {
transaction.sinter(keys);
@@ -736,7 +733,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void sInterStore(String destKey, String... keys) {
+ public void sInterStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sinterstore(destKey, keys);
@@ -748,7 +745,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean sIsMember(String key, String value) {
+ public Boolean sIsMember(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.sismember(key, value);
@@ -761,7 +758,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set sMembers(String key) {
+ public Set sMembers(byte[] key) {
try {
if (isQueueing()) {
transaction.smembers(key);
@@ -774,7 +771,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean sMove(String srcKey, String destKey, String value) {
+ public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
try {
if (isQueueing()) {
transaction.smove(srcKey, destKey, value);
@@ -787,7 +784,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String sPop(String key) {
+ public byte[] sPop(byte[] key) {
try {
if (isQueueing()) {
transaction.spop(key);
@@ -800,7 +797,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String sRandMember(String key) {
+ public byte[] sRandMember(byte[] key) {
try {
if (isQueueing()) {
transaction.srandmember(key);
@@ -813,7 +810,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean sRem(String key, String value) {
+ public Boolean sRem(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.srem(key, value);
@@ -826,7 +823,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set sUnion(String... keys) {
+ public Set sUnion(byte[]... keys) {
try {
if (isQueueing()) {
transaction.sunion(keys);
@@ -839,7 +836,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void sUnionStore(String destKey, String... keys) {
+ public void sUnionStore(byte[] destKey, byte[]... keys) {
try {
if (isQueueing()) {
transaction.sunionstore(destKey, keys);
@@ -855,7 +852,7 @@ public class JedisConnection implements RedisConnection {
//
@Override
- public Boolean zAdd(String key, double score, String value) {
+ public Boolean zAdd(byte[] key, double score, byte[] value) {
try {
if (isQueueing()) {
transaction.zadd(key, score, value);
@@ -868,7 +865,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zCard(String key) {
+ public Integer zCard(byte[] key) {
try {
if (isQueueing()) {
transaction.zcard(key);
@@ -881,7 +878,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zCount(String key, double min, double max) {
+ public Integer zCount(byte[] key, double min, double max) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -893,7 +890,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Double zIncrBy(String key, double increment, String value) {
+ public Double zIncrBy(byte[] key, double increment, byte[] value) {
try {
if (isQueueing()) {
transaction.zincrby(key, increment, value);
@@ -906,7 +903,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) {
+ public Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -920,7 +917,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zInterStore(String destKey, String... sets) {
+ public Integer zInterStore(byte[] destKey, byte[]... sets) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -932,7 +929,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRange(String key, int start, int end) {
+ public Set zRange(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.zrange(key, start, end);
@@ -945,7 +942,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRangeWithScore(String key, int start, int end) {
+ public Set zRangeWithScore(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.zrangeWithScores(key, start, end);
@@ -958,7 +955,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRangeByScore(String key, double min, double max) {
+ public Set zRangeByScore(byte[] key, double min, double max) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -970,7 +967,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRangeByScoreWithScore(String key, double min, double max) {
+ public Set zRangeByScoreWithScore(byte[] key, double min, double max) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -982,7 +979,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRevRangeWithScore(String key, int start, int end) {
+ public Set zRevRangeWithScore(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.zrangeWithScores(key, start, end);
@@ -995,7 +992,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRangeByScore(String key, double min, double max, int offset, int count) {
+ public Set zRangeByScore(byte[] key, double min, double max, int offset, int count) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1007,7 +1004,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRangeByScoreWithScore(String key, double min, double max, int offset, int count) {
+ public Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1019,7 +1016,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zRank(String key, String value) {
+ public Integer zRank(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.zrank(key, value);
@@ -1032,7 +1029,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean zRem(String key, String value) {
+ public Boolean zRem(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.zrem(key, value);
@@ -1045,7 +1042,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zRemRange(String key, int start, int end) {
+ public Integer zRemRange(byte[] key, int start, int end) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1057,7 +1054,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zRemRangeByScore(String key, double min, double max) {
+ public Integer zRemRangeByScore(byte[] key, double min, double max) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1069,7 +1066,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set zRevRange(String key, int start, int end) {
+ public Set zRevRange(byte[] key, int start, int end) {
try {
if (isQueueing()) {
transaction.zrevrange(key, start, end);
@@ -1082,7 +1079,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zRevRank(String key, String value) {
+ public Integer zRevRank(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.zrevrank(key, value);
@@ -1095,7 +1092,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Double zScore(String key, String value) {
+ public Double zScore(byte[] key, byte[] value) {
try {
if (isQueueing()) {
transaction.zscore(key, value);
@@ -1108,7 +1105,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) {
+ public Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1122,7 +1119,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Integer zUnionStore(String destKey, String... sets) {
+ public Integer zUnionStore(byte[] destKey, byte[]... sets) {
try {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -1138,7 +1135,7 @@ public class JedisConnection implements RedisConnection {
//
@Override
- public Boolean hSet(String key, String field, String value) {
+ public Boolean hSet(byte[] key, byte[] field, byte[] value) {
try {
if (isQueueing()) {
transaction.hset(key, field, value);
@@ -1151,7 +1148,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean hSetNX(String key, String field, String value) {
+ public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
try {
if (isQueueing()) {
transaction.hsetnx(key, field, value);
@@ -1164,7 +1161,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean hDel(String key, String field) {
+ public Boolean hDel(byte[] key, byte[] field) {
try {
if (isQueueing()) {
transaction.hdel(key, field);
@@ -1177,7 +1174,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Boolean hExists(String key, String field) {
+ public Boolean hExists(byte[] key, byte[] field) {
try {
if (isQueueing()) {
transaction.hexists(key, field);
@@ -1190,7 +1187,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public String hGet(String key, String field) {
+ public byte[] hGet(byte[] key, byte[] field) {
try {
if (isQueueing()) {
transaction.hget(key, field);
@@ -1203,20 +1200,20 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set hGetAll(String key) {
+ public Map hGetAll(byte[] key) {
try {
if (isQueueing()) {
transaction.hgetAll(key);
return null;
}
- return JedisUtils.convert(jedis.hgetAll(key));
+ return jedis.hgetAll(key);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public Integer hIncrBy(String key, String field, int delta) {
+ public Integer hIncrBy(byte[] key, byte[] field, int delta) {
try {
if (isQueueing()) {
transaction.hincrBy(key, field, delta);
@@ -1229,20 +1226,20 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public Set hKeys(String key) {
+ public Set hKeys(byte[] key) {
try {
if (isQueueing()) {
transaction.hkeys(key);
return null;
}
- return new LinkedHashSet(jedis.hkeys(key));
+ return jedis.hkeys(key);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public Integer hLen(String key) {
+ public Integer hLen(byte[] key) {
try {
if (isQueueing()) {
transaction.hlen(key);
@@ -1255,7 +1252,7 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public List hMGet(String key, String... fields) {
+ public List hMGet(byte[] key, byte[]... fields) {
try {
if (isQueueing()) {
transaction.hmget(key, fields);
@@ -1268,26 +1265,25 @@ public class JedisConnection implements RedisConnection {
}
@Override
- public void hMSet(String key, String[] fields, String[] values) {
- Map param = JedisUtils.convert(fields, values);
+ public void hMSet(byte[] key, Map tuple) {
try {
if (isQueueing()) {
- transaction.hmset(key, param);
+ transaction.hmset(key, tuple);
}
- jedis.hmset(key, param);
+ jedis.hmset(key, tuple);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
- public List hVals(String key) {
+ public List hVals(byte[] key) {
try {
if (isQueueing()) {
transaction.hvals(key);
return null;
}
- return jedis.hvals(key);
+ return new ArrayList(jedis.hvals(key));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java
index 296c7f672..1eb782033 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java
@@ -117,10 +117,11 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
int size = getPoolSize();
pool = new JedisPool(shardInfo);
pool.setResourcesNumber(size);
+ pool.init();
}
}
- public void destroy() throws Exception {
+ public void destroy() {
if (usePool && pool != null) {
pool.destroy();
pool = null;
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java
index a1f097631..0306d72c5 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java
@@ -28,9 +28,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.datastore.redis.RedisConnectionFailureException;
import org.springframework.datastore.redis.UncategorizedRedisException;
-import org.springframework.datastore.redis.connection.DefaultEntry;
import org.springframework.datastore.redis.connection.DefaultTuple;
-import org.springframework.datastore.redis.connection.RedisHashCommands.Entry;
import org.springframework.datastore.redis.connection.RedisZSetCommands.Tuple;
import redis.clients.jedis.JedisException;
@@ -79,19 +77,21 @@ public abstract class JedisUtils {
static Set convertJedisTuple(Set tuples) {
Set value = new LinkedHashSet(tuples.size());
for (redis.clients.jedis.Tuple tuple : tuples) {
- value.add(new DefaultTuple(tuple.getElement(), tuple.getScore()));
+ value.add(new DefaultTuple(tuple.getBinaryElement(), tuple.getScore()));
}
return value;
}
- static Set convert(Map hgetAll) {
- Set entries = new LinkedHashSet(hgetAll.size());
- for (Map.Entry entry : hgetAll.entrySet()) {
- entries.add(new DefaultEntry(entry.getKey(), entry.getValue()));
- }
+ static byte[][] convert(Map hgetAll) {
+ byte[][] result = new byte[hgetAll.size() * 2][];
- return entries;
+ int index = 0;
+ for (Map.Entry entry : hgetAll.entrySet()) {
+ result[index++] = entry.getKey();
+ result[index++] = entry.getValue();
+ }
+ return result;
}
static Map convert(String[] fields, String[] values) {
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java
index 371ba1876..52ea0341f 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java
@@ -15,10 +15,12 @@
*/
package org.springframework.datastore.redis.connection.jredis;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.jredis.JRedis;
@@ -30,16 +32,19 @@ import org.springframework.datastore.redis.connection.DataType;
import org.springframework.datastore.redis.connection.RedisConnection;
/**
+ * JRedis based implementation.
+ *
* @author Costin Leau
*/
public class JredisConnection implements RedisConnection {
private final JRedis jredis;
- private final String encoding;
- public JredisConnection(JRedis jredis, String encoding) {
+ private final Charset charset;
+
+ public JredisConnection(JRedis jredis, Charset charset) {
this.jredis = jredis;
- this.encoding = encoding;
+ this.charset = charset;
}
protected DataAccessException convertJedisAccessException(Exception ex) {
@@ -55,11 +60,6 @@ public class JredisConnection implements RedisConnection {
}
- @Override
- public String getEncoding() {
- return encoding;
- }
-
@Override
public JRedis getNativeConnection() {
return jredis;
@@ -85,9 +85,9 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Integer del(String... keys) {
+ public Integer del(byte[]... keys) {
try {
- return Integer.valueOf((int) jredis.del(keys));
+ return Integer.valueOf((int) jredis.del(JredisUtils.convertMultiple(charset, keys)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -108,27 +108,27 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Boolean exists(String key) {
+ public Boolean exists(byte[] key) {
try {
- return jredis.exists(key);
+ return jredis.exists(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean expire(String key, int seconds) {
+ public Boolean expire(byte[] key, int seconds) {
try {
- return jredis.expire(key, seconds);
+ return jredis.expire(JredisUtils.convert(charset, key), seconds);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Collection keys(String pattern) {
+ public Collection keys(byte[] pattern) {
try {
- return jredis.keys(pattern);
+ return JredisUtils.convert(charset, jredis.keys(JredisUtils.convert(charset, pattern)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -140,32 +140,32 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Boolean persist(String key) {
+ public Boolean persist(byte[] key) {
throw new UnsupportedOperationException();
}
@Override
- public String randomKey() {
+ public byte[] randomKey() {
try {
- return jredis.randomkey();
+ return JredisUtils.convert(charset, jredis.randomkey());
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void rename(String oldName, String newName) {
+ public void rename(byte[] oldName, byte[] newName) {
try {
- jredis.rename(oldName, newName);
+ jredis.rename(JredisUtils.convert(charset, oldName), JredisUtils.convert(charset, newName));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean renameNX(String oldName, String newName) {
+ public Boolean renameNX(byte[] oldName, byte[] newName) {
try {
- return jredis.renamenx(oldName, newName);
+ return jredis.renamenx(JredisUtils.convert(charset, oldName), JredisUtils.convert(charset, newName));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -177,18 +177,18 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Integer ttl(String key) {
+ public Integer ttl(byte[] key) {
try {
- return Integer.valueOf((int) jredis.ttl(key));
+ return Integer.valueOf((int) jredis.ttl(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public DataType type(String key) {
+ public DataType type(byte[] key) {
try {
- return JredisUtils.convertDataType(jredis.type(key));
+ return JredisUtils.convertDataType(jredis.type(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -200,7 +200,7 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public void watch(String... keys) {
+ public void watch(byte[]... keys) {
throw new UnsupportedOperationException();
}
@@ -209,123 +209,122 @@ public class JredisConnection implements RedisConnection {
//
@Override
- public String get(String key) {
+ public byte[] get(byte[] key) {
try {
- return JredisUtils.convertToString(jredis.get(key), encoding);
+ return jredis.get(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void set(String key, String value) {
+ public void set(byte[] key, byte[] value) {
try {
- jredis.set(key, value);
+ jredis.set(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String getSet(String key, String value) {
+ public byte[] getSet(byte[] key, byte[] value) {
try {
- return JredisUtils.convertToString(jredis.getset(key, value), encoding);
- } catch (RedisException ex) {
- throw JredisUtils.convertJredisAccessException(ex);
- }
- }
-
-
- @Override
- public Integer append(String key, String value) {
- try {
- return Integer.valueOf((int) jredis.append(key, value));
+ return jredis.getset(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public List mGet(String... keys) {
+ public Integer append(byte[] key, byte[] value) {
try {
- return JredisUtils.convertToStringCollection(jredis.mget(keys), encoding, List.class);
+ return Integer.valueOf((int) jredis.append(JredisUtils.convert(charset, key), value));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void mSet(String[] keys, String[] values) {
+ public List mGet(byte[]... keys) {
try {
- jredis.mset(JredisUtils.convert(keys, values));
+ return jredis.mget(JredisUtils.convertMultiple(charset, keys));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void mSetNX(String[] keys, String[] values) {
+ public void mSet(Map tuple) {
try {
- jredis.msetnx(JredisUtils.convert(keys, values));
+ jredis.mset(JredisUtils.convert(charset, tuple));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void setEx(String key, int seconds, String value) {
+ public void mSetNX(Map tuple) {
+ try {
+ jredis.msetnx(JredisUtils.convert(charset, tuple));
+ } catch (RedisException ex) {
+ throw JredisUtils.convertJredisAccessException(ex);
+ }
+ }
+
+ @Override
+ public void setEx(byte[] key, int seconds, byte[] value) {
throw new UnsupportedOperationException();
}
@Override
- public Boolean setNX(String key, String value) {
+ public Boolean setNX(byte[] key, byte[] value) {
try {
- return jredis.setnx(key, value);
+ return jredis.setnx(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String substr(String key, int start, int end) {
+ public byte[] substr(byte[] key, int start, int end) {
try {
- return JredisUtils.convertToString(jredis.substr(key, (long) start, (long) end), encoding);
+ return jredis.substr(JredisUtils.convert(charset, key), (long) start, (long) end);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer decr(String key) {
+ public Integer decr(byte[] key) {
try {
- return (int) jredis.decr(key);
+ return (int) jredis.decr(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer decrBy(String key, int value) {
+ public Integer decrBy(byte[] key, int value) {
try {
- return (int) jredis.decrby(key, value);
+ return (int) jredis.decrby(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer incr(String key) {
+ public Integer incr(byte[] key) {
try {
- return (int) jredis.incr(key);
+ return (int) jredis.incr(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer incrBy(String key, int value) {
+ public Integer incrBy(byte[] key, int value) {
try {
- return (int) jredis.incrby(key, value);
+ return (int) jredis.incrby(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -336,46 +335,46 @@ public class JredisConnection implements RedisConnection {
//
@Override
- public List bLPop(int timeout, String... keys) {
+ public List bLPop(int timeout, byte[]... keys) {
throw new UnsupportedOperationException();
}
@Override
- public List bRPop(int timeout, String... keys) {
+ public List bRPop(int timeout, byte[]... keys) {
throw new UnsupportedOperationException();
}
@Override
- public String lIndex(String key, int index) {
+ public byte[] lIndex(byte[] key, int index) {
try {
- return JredisUtils.convertToString(jredis.lindex(key, (long) index), encoding);
+ return jredis.lindex(JredisUtils.convert(charset, key), (long) index);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer lLen(String key) {
+ public Integer lLen(byte[] key) {
try {
- return Integer.valueOf((int) jredis.llen(key));
+ return Integer.valueOf((int) jredis.llen(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String lPop(String key) {
+ public byte[] lPop(byte[] key) {
try {
- return JredisUtils.convertToString(jredis.lpop(key), encoding);
+ return jredis.lpop(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer lPush(String key, String value) {
+ public Integer lPush(byte[] key, byte[] value) {
try {
- jredis.lpush(key, value);
+ jredis.lpush(JredisUtils.convert(charset, key), value);
return null;
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
@@ -383,66 +382,65 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public List lRange(String key, int start, int end) {
+ public List lRange(byte[] key, int start, int end) {
try {
- List lrange = jredis.lrange(key, start, end);
+ List lrange = jredis.lrange(JredisUtils.convert(charset, key), start, end);
- return JredisUtils.convertToStringCollection(lrange, encoding, List.class);
+ return lrange;
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer lRem(String key, int count, String value) {
+ public Integer lRem(byte[] key, int count, byte[] value) {
try {
- Integer.valueOf((int) jredis.lrem(key, value, count));
- return null;
+ return Integer.valueOf((int) jredis.lrem(JredisUtils.convert(charset, key), value, count));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void lSet(String key, int index, String value) {
+ public void lSet(byte[] key, int index, byte[] value) {
try {
- jredis.lset(key, index, value);
+ jredis.lset(JredisUtils.convert(charset, key), index, value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void lTrim(String key, int start, int end) {
+ public void lTrim(byte[] key, int start, int end) {
try {
- jredis.ltrim(key, start, end);
+ jredis.ltrim(JredisUtils.convert(charset, key), start, end);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String rPop(String key) {
+ public byte[] rPop(byte[] key) {
try {
- return JredisUtils.convertToString(jredis.rpop(key), encoding);
+ return jredis.rpop(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String rPopLPush(String srcKey, String dstKey) {
+ public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
try {
- return JredisUtils.convertToString(jredis.rpoplpush(srcKey, dstKey), encoding);
+ return jredis.rpoplpush(JredisUtils.convert(charset, srcKey), JredisUtils.convert(charset, dstKey));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer rPush(String key, String value) {
+ public Integer rPush(byte[] key, byte[] value) {
try {
- jredis.rpush(key, value);
+ jredis.rpush(JredisUtils.convert(charset, key), value);
return null;
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
@@ -454,40 +452,40 @@ public class JredisConnection implements RedisConnection {
//
@Override
- public Boolean sAdd(String key, String value) {
+ public Boolean sAdd(byte[] key, byte[] value) {
try {
- return jredis.sadd(key, value);
+ return jredis.sadd(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer sCard(String key) {
+ public Integer sCard(byte[] key) {
try {
- return Integer.valueOf((int) jredis.scard(key));
+ return Integer.valueOf((int) jredis.scard(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set sDiff(String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public Set sDiff(byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
List result = jredis.sdiff(set1, sets);
- return JredisUtils.convertToStringCollection(result, encoding, Set.class);
+ return new LinkedHashSet(result);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void sDiffStore(String destKey, String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public void sDiffStore(byte[] destKey, byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
jredis.sdiffstore(set1, sets);
@@ -497,22 +495,22 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Set sInter(String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public Set sInter(byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
List result = jredis.sinter(set1, sets);
- return JredisUtils.convertToStringCollection(result, encoding, Set.class);
+ return new LinkedHashSet(result);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void sInterStore(String destKey, String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public void sInterStore(byte[] destKey, byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
jredis.sinterstore(set1, sets);
@@ -522,76 +520,75 @@ public class JredisConnection implements RedisConnection {
}
@Override
- public Boolean sIsMember(String key, String value) {
+ public Boolean sIsMember(byte[] key, byte[] value) {
try {
- return jredis.sismember(key, value);
+ return jredis.sismember(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set sMembers(String key) {
+ public Set sMembers(byte[] key) {
try {
- return JredisUtils.convertToStringCollection(jredis.smembers(key), encoding, Set.class);
+ return new LinkedHashSet(jredis.smembers(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean sMove(String srcKey, String destKey, String value) {
+ public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
try {
- return jredis.smove(srcKey, destKey, value);
+ return jredis.smove(JredisUtils.convert(charset, srcKey), JredisUtils.convert(charset, destKey), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String sPop(String key) {
+ public byte[] sPop(byte[] key) {
try {
- return JredisUtils.convertToString(jredis.spop(key), encoding);
+ return jredis.spop(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String sRandMember(String key) {
+ public byte[] sRandMember(byte[] key) {
try {
- return JredisUtils.convertToString(jredis.srandmember(key), encoding);
+ return jredis.srandmember(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean sRem(String key, String value) {
+ public Boolean sRem(byte[] key, byte[] value) {
try {
- return jredis.srem(key, value);
+ return jredis.srem(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set sUnion(String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public Set sUnion(byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
- List result = jredis.sunion(set1, sets);
- return JredisUtils.convertToStringCollection(result, encoding, Set.class);
+ return new LinkedHashSet(jredis.sunion(set1, sets));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public void sUnionStore(String destKey, String... keys) {
- String set1 = keys[0];
- String[] sets = Arrays.copyOfRange(keys, 1, keys.length);
+ public void sUnionStore(byte[] destKey, byte[]... keys) {
+ String set1 = JredisUtils.convert(charset, keys[0]);
+ String[] sets = JredisUtils.convertMultiple(charset, Arrays.copyOfRange(keys, 1, keys.length));
try {
jredis.sunionstore(set1, sets);
@@ -606,154 +603,153 @@ public class JredisConnection implements RedisConnection {
//
@Override
- public Boolean zAdd(String key, double score, String value) {
+ public Boolean zAdd(byte[] key, double score, byte[] value) {
try {
- return jredis.zadd(key, score, value);
+ return jredis.zadd(JredisUtils.convert(charset, key), score, value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer zCard(String key) {
+ public Integer zCard(byte[] key) {
try {
- return Integer.valueOf((int) jredis.zcard(key));
+ return Integer.valueOf((int) jredis.zcard(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer zCount(String key, double min, double max) {
+ public Integer zCount(byte[] key, double min, double max) {
try {
- return Integer.valueOf((int) jredis.zcount(key, min, max));
+ return Integer.valueOf((int) jredis.zcount(JredisUtils.convert(charset, key), min, max));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Double zIncrBy(String key, double increment, String value) {
+ public Double zIncrBy(byte[] key, double increment, byte[] value) {
try {
- return jredis.zincrby(key, increment, value);
+ return jredis.zincrby(JredisUtils.convert(charset, key), increment, value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) {
+ public Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
throw new UnsupportedOperationException();
}
@Override
- public Integer zInterStore(String destKey, String... sets) {
+ public Integer zInterStore(byte[] destKey, byte[]... sets) {
throw new UnsupportedOperationException();
}
@Override
- public Set zRange(String key, int start, int end) {
+ public Set zRange(byte[] key, int start, int end) {
try {
- return JredisUtils.convertToStringCollection(jredis.zrange(key, (long) start, (long) end), encoding,
- Set.class);
+ return new LinkedHashSet(jredis.zrange(JredisUtils.convert(charset, key), (long) start, (long) end));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set zRangeWithScore(String key, int start, int end) {
+ public Set zRangeWithScore(byte[] key, int start, int end) {
throw new UnsupportedOperationException();
}
@Override
- public Set zRangeByScore(String key, double min, double max) {
+ public Set zRangeByScore(byte[] key, double min, double max) {
try {
- return JredisUtils.convertToStringCollection(jredis.zrangebyscore(key, min, max), encoding, Set.class);
+ return new LinkedHashSet(jredis.zrangebyscore(JredisUtils.convert(charset, key), min, max));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set zRangeByScoreWithScore(String key, double min, double max) {
+ public Set zRangeByScoreWithScore(byte[] key, double min, double max) {
throw new UnsupportedOperationException();
}
@Override
- public Set zRangeByScore(String key, double min, double max, int offset, int count) {
+ public Set zRangeByScore(byte[] key, double min, double max, int offset, int count) {
throw new UnsupportedOperationException();
}
@Override
- public Set zRangeByScoreWithScore(String key, double min, double max, int offset, int count) {
+ public Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count) {
throw new UnsupportedOperationException();
}
@Override
- public Integer zRank(String key, String value) {
+ public Integer zRank(byte[] key, byte[] value) {
try {
- return Integer.valueOf((int) jredis.zrank(key, value));
+ return Integer.valueOf((int) jredis.zrank(JredisUtils.convert(charset, key), value));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean zRem(String key, String value) {
+ public Boolean zRem(byte[] key, byte[] value) {
try {
- return jredis.zrem(key, value);
+ return jredis.zrem(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer zRemRange(String key, int start, int end) {
+ public Integer zRemRange(byte[] key, int start, int end) {
try {
- return Integer.valueOf((int) jredis.zremrangebyrank(key, start, end));
+ return Integer.valueOf((int) jredis.zremrangebyrank(JredisUtils.convert(charset, key), start, end));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer zRemRangeByScore(String key, double min, double max) {
+ public Integer zRemRangeByScore(byte[] key, double min, double max) {
try {
- return Integer.valueOf((int) jredis.zremrangebyscore(key, min, max));
+ return Integer.valueOf((int) jredis.zremrangebyscore(JredisUtils.convert(charset, key), min, max));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set zRevRange(String key, int start, int end) {
+ public Set zRevRange(byte[] key, int start, int end) {
try {
- return JredisUtils.convertToStringCollection(jredis.zrevrange(key, start, end), encoding, Set.class);
+ return new LinkedHashSet(jredis.zrevrange(JredisUtils.convert(charset, key), start, end));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set zRevRangeWithScore(String key, int start, int end) {
+ public Set zRevRangeWithScore(byte[] key, int start, int end) {
throw new UnsupportedOperationException();
}
@Override
- public Integer zRevRank(String key, String value) {
+ public Integer zRevRank(byte[] key, byte[] value) {
try {
- return Integer.valueOf((int) jredis.zrevrank(key, value));
+ return Integer.valueOf((int) jredis.zrevrank(JredisUtils.convert(charset, key), value));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Double zScore(String key, String value) {
+ public Double zScore(byte[] key, byte[] value) {
try {
- return jredis.zscore(key, value);
+ return jredis.zscore(JredisUtils.convert(charset, key), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
@@ -765,102 +761,103 @@ public class JredisConnection implements RedisConnection {
//
@Override
- public Integer zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) {
+ public Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
throw new UnsupportedOperationException();
}
@Override
- public Integer zUnionStore(String destKey, String... sets) {
+ public Integer zUnionStore(byte[] destKey, byte[]... sets) {
throw new UnsupportedOperationException();
}
@Override
- public Boolean hDel(String key, String field) {
+ public Boolean hDel(byte[] key, byte[] field) {
try {
- return jredis.hdel(key, field);
+ return jredis.hdel(JredisUtils.convert(charset, key), JredisUtils.convert(charset, field));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean hExists(String key, String field) {
+ public Boolean hExists(byte[] key, byte[] field) {
try {
- return jredis.hexists(key, field);
+ return jredis.hexists(JredisUtils.convert(charset, key), JredisUtils.convert(charset, field));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public String hGet(String key, String field) {
+ public byte[] hGet(byte[] key, byte[] field) {
try {
- return JredisUtils.convertToString(jredis.hget(key, field), encoding);
+ return jredis.hget(JredisUtils.convert(charset, key), JredisUtils.convert(charset, field));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Set hGetAll(String key) {
+ public Map hGetAll(byte[] key) {
try {
- return JredisUtils.convert(jredis.hgetall(key), encoding);
+ return JredisUtils.convertMap(charset, jredis.hgetall(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer hIncrBy(String key, String field, int delta) {
+ public Integer hIncrBy(byte[] key, byte[] field, int delta) {
throw new UnsupportedOperationException();
}
@Override
- public Set hKeys(String key) {
+ public Set hKeys(byte[] key) {
try {
- return new LinkedHashSet(jredis.hkeys(key));
+ return new LinkedHashSet(JredisUtils.convert(charset,
+ jredis.hkeys(JredisUtils.convert(charset, key))));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Integer hLen(String key) {
+ public Integer hLen(byte[] key) {
try {
- return Integer.valueOf((int) jredis.hlen(key));
+ return Integer.valueOf((int) jredis.hlen(JredisUtils.convert(charset, key)));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public List hMGet(String key, String... fields) {
+ public List hMGet(byte[] key, byte[]... fields) {
throw new UnsupportedOperationException();
}
@Override
- public void hMSet(String key, String[] fields, String[] values) {
+ public void hMSet(byte[] key, Map values) {
throw new UnsupportedOperationException();
}
@Override
- public Boolean hSet(String key, String field, String value) {
+ public Boolean hSet(byte[] key, byte[] field, byte[] value) {
try {
- return jredis.hset(key, field, value);
+ return jredis.hset(JredisUtils.convert(charset, key), JredisUtils.convert(charset, field), value);
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
}
@Override
- public Boolean hSetNX(String key, String field, String value) {
+ public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
throw new UnsupportedOperationException();
}
@Override
- public List hVals(String key) {
+ public List hVals(byte[] key) {
try {
- return JredisUtils.convertToStringCollection(jredis.hvals(key), encoding, List.class);
+ return jredis.hvals(JredisUtils.convert(charset, key));
} catch (RedisException ex) {
throw JredisUtils.convertJredisAccessException(ex);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnectionFactory.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnectionFactory.java
index 015d36793..4037c0783 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnectionFactory.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnectionFactory.java
@@ -15,6 +15,8 @@
*/
package org.springframework.datastore.redis.connection.jredis;
+import java.nio.charset.Charset;
+
import org.jredis.JRedis;
import org.jredis.connector.ConnectionSpec;
import org.jredis.connector.Connection.Socket.Property;
@@ -36,7 +38,6 @@ import org.springframework.util.StringUtils;
*/
public class JredisConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
- private String encoding = "UTF-8";
private ConnectionSpec connectionSpec;
private String password;
@@ -49,6 +50,9 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
private int poolSize = 5;
+ private Charset charset = Charset.forName("UTF8");
+
+
/**
* Constructs a new JredisConnectionFactory instance.
*/
@@ -88,7 +92,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
this.connectionSpec = connectionSpec;
}
-
@Override
public void afterPropertiesSet() {
if (StringUtils.hasLength(password)) {
@@ -117,7 +120,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
@Override
public RedisConnection getConnection() {
- return new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec)), getEncoding());
+ return new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec)), charset);
}
@@ -126,22 +129,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
return null;
}
- /**
- * Returns the encoding.
- *
- * @return Returns the encoding
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * @param encoding The encoding to set.
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
/**
* @return the password
*/
@@ -191,4 +178,21 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
this.poolSize = poolSize;
usePool = true;
}
+
+
+ /**
+ *
+ * @return
+ */
+ public Charset getCharset() {
+ return charset;
+ }
+
+
+ /**
+ * @param charset
+ */
+ public void setCharset(Charset charset) {
+ this.charset = charset;
+ }
}
\ No newline at end of file
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java
index 8bb44a9b3..38a5e73b6 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java
@@ -16,23 +16,18 @@
package org.springframework.datastore.redis.connection.jredis;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.jredis.RedisException;
import org.jredis.RedisType;
import org.springframework.dao.DataAccessException;
-import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.datastore.redis.connection.DataType;
-import org.springframework.datastore.redis.connection.DefaultEntry;
-import org.springframework.datastore.redis.connection.RedisHashCommands.Entry;
/**
* Helper class featuring methods for JRedis connection handling, providing support for exception translation.
@@ -45,27 +40,16 @@ public abstract class JredisUtils {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
- static String convertToString(byte[] bytes, String encoding) {
- try {
- return new String(bytes, encoding);
- } catch (UnsupportedEncodingException ex) {
- throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex);
- }
+ static String convert(Charset charset, byte[] bytes) {
+ return new String(bytes, charset);
}
- static > T convertToStringCollection(List bytes, String encoding, Class collectionType) {
-
- Collection col = (List.class.isAssignableFrom(collectionType) ? new ArrayList(bytes.size())
- : new LinkedHashSet(bytes.size()));
-
- try {
- for (byte[] bs : bytes) {
- col.add(new String(bs, encoding));
- }
- return (T) col;
- } catch (UnsupportedEncodingException ex) {
- throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex);
+ static String[] convertMultiple(Charset charset, byte[]... bytes) {
+ String[] result = new String[bytes.length];
+ for (int i = 0; i < bytes.length; i++) {
+ result[i] = new String(bytes[i], charset);
}
+ return result;
}
static DataType convertDataType(RedisType type) {
@@ -87,23 +71,31 @@ public abstract class JredisUtils {
return null;
}
- static Set convert(Map map, String encoding) {
- Set entries = new LinkedHashSet(map.size());
- try {
- for (Map.Entry entry : map.entrySet()) {
- entries.add(new DefaultEntry(entry.getKey(), new String(entry.getValue(), encoding)));
- }
- } catch (UnsupportedEncodingException ex) {
- throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex);
+ static Map convertMap(Charset charset, Map map) {
+ Map result = new LinkedHashMap(map.size());
+ for (Map.Entry entry : map.entrySet()) {
+ result.put(entry.getKey().getBytes(charset), entry.getValue());
}
- return entries;
+ return result;
}
- static Map convert(String[] keys, String[] values) {
- Map result = new LinkedHashMap(keys.length);
+ static Collection convert(Charset charset, List keys) {
+ Collection list = new ArrayList(keys.size());
- for (int i = 0; i < values.length; i++) {
- result.put(keys[i], values[i].getBytes());
+ for (String string : keys) {
+ list.add(string.getBytes(charset));
+ }
+ return list;
+ }
+
+ static byte[] convert(Charset charset, String string) {
+ return string.getBytes(charset);
+ }
+
+ static Map convert(Charset charset, Map tuple) {
+ Map result = new LinkedHashMap(tuple.size());
+ for (Map.Entry entry : tuple.entrySet()) {
+ result.put(new String(entry.getKey(), charset), entry.getValue());
}
return result;
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java
new file mode 100644
index 000000000..1c1e330c3
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.datastore.redis.core;
+
+import java.util.List;
+
+/**
+ * List operations bound to a certain key.
+ *
+ * @author Costin Leau
+ */
+public interface BoundListOperations extends KeyBound {
+
+ List range(int start, int end);
+
+ void trim(int start, int end);
+
+ Integer length();
+
+ Integer leftPush(V value);
+
+ Integer rightPush(V value);
+
+ V leftPop();
+
+ V rightPop();
+
+ Integer remove(int i, Object value);
+
+ V index(int index);
+}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java
new file mode 100644
index 000000000..c1afe7f4a
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.datastore.redis.core;
+
+import java.util.Set;
+
+/**
+ * Set operations bound to a certain key.
+ *
+ * @author Costin Leau
+ */
+public interface BoundSetOperations extends KeyBound {
+
+ Set diff(K... keys);
+
+ void diffAndStore(K destKey, K... keys);
+
+ RedisOperations getOperations();
+
+ Set intersect(K... keys);
+
+ void intersectAndStore(K destKey, K... keys);
+
+ Set union(K... keys);
+
+ void unionAndStore(K destKey, K... keys);
+
+ Boolean add(V value);
+
+ boolean isMember(Object o);
+
+ Set members();
+
+ boolean remove(Object o);
+
+ int size();
+}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundZSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundZSetOperations.java
new file mode 100644
index 000000000..72d1e2dcd
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundZSetOperations.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.datastore.redis.core;
+
+import java.util.Set;
+
+
+/**
+ * ZSet (or SortedSet) operations bound to a certain key.
+ *
+ * @author Costin Leau
+ */
+public interface BoundZSetOperations extends KeyBound {
+
+ RedisOperations getOperations();
+
+ void intersectAndStore(K destKey, K... keys);
+
+ Set range(int start, int end);
+
+ Set rangeByScore(double min, double max);
+
+ void removeRange(int start, int end);
+
+ void removeRangeByScore(double min, double max);
+
+ void unionAndStore(K destKey, K... keys);
+
+ boolean add(V value, double score);
+
+ Integer rank(Object o);
+
+ boolean remove(Object o);
+
+ int size();
+
+ Set reverseRange(int start, int end);
+}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java
new file mode 100644
index 000000000..82ebaf363
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.datastore.redis.core;
+
+import java.util.List;
+
+
+/**
+ * Default implementation for {@link BoundListOperations}.
+ *
+ * @author Costin Leau
+ */
+public class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations {
+
+ private final ListOperations ops;
+
+ public DefaultBoundListOperations(K key, RedisTemplate template) {
+ super(key);
+ this.ops = template.listOps();
+ }
+
+ @Override
+ public V index(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public V leftPop() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Integer leftPush(V value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Integer length() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List range(int start, int end) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Integer remove(int i, Object value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public V rightPop() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Integer rightPush(V value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void trim(int start, int end) {
+ throw new UnsupportedOperationException();
+ }
+}
\ No newline at end of file
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java
new file mode 100644
index 000000000..ff9a529ef
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.datastore.redis.core;
+
+import java.util.Set;
+
+/**
+ * Default implementation for {@link BoundSetOperations}.
+ *
+ * @author Costin Leau
+ */
+class DefaultBoundSetOperations extends DefaultKeyBound implements BoundSetOperations {
+
+ private final SetOperations ops;
+
+
+ DefaultBoundSetOperations(K key, RedisTemplate template) {
+ super(key);
+ this.ops = template.setOps();
+ }
+
+ @Override
+ public Boolean add(V value) {
+ return ops.add(getKey(), value);
+ }
+
+ @Override
+ public Set diff(K... keys) {
+ return ops.diff(getKey(), keys);
+ }
+
+ @Override
+ public void diffAndStore(K destKey, K... keys) {
+ ops.diffAndStore(getKey(), destKey, keys);
+ }
+
+ @Override
+ public RedisOperations getOperations() {
+ return ops.getOperations();
+ }
+
+ @Override
+ public Set intersect(K... keys) {
+ return ops.intersect(getKey(), keys);
+ }
+
+ @Override
+ public void intersectAndStore(K destKey, K... keys) {
+ ops.intersectAndStore(getKey(), destKey, keys);
+ }
+
+ @Override
+ public boolean isMember(Object o) {
+ return ops.isMember(getKey(), o);
+ }
+
+ @Override
+ public Set members() {
+ return ops.members(getKey());
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return ops.remove(getKey(), o);
+ }
+
+ @Override
+ public int size() {
+ return ops.size(getKey());
+ }
+
+ @Override
+ public Set union(K... keys) {
+ return ops.union(getKey(), keys);
+ }
+
+ @Override
+ public void unionAndStore(K destKey, K... keys) {
+ ops.unionAndStore(getKey(), destKey, keys);
+ }
+}
\ No newline at end of file
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundZSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundZSetOperations.java
new file mode 100644
index 000000000..8b3fe5c6f
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundZSetOperations.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.datastore.redis.core;
+
+import java.util.Set;
+
+/**
+ * Default implementation for {@link BoundZSetOperations}.
+ *
+ * @author Costin Leau
+ */
+class DefaultBoundZSetOperations extends DefaultKeyBound implements BoundZSetOperations {
+
+ private final ZSetOperations ops;
+
+ public DefaultBoundZSetOperations(K key, RedisTemplate template) {
+ super(key);
+ this.ops = template.zSetOps();
+ }
+
+ @Override
+ public boolean add(V value, double score) {
+ return ops.add(getKey(), value, score);
+ }
+
+ @Override
+ public RedisOperations getOperations() {
+ return ops.getOperations();
+ }
+
+ @Override
+ public void intersectAndStore(K destKey, K... keys) {
+ ops.intersectAndStore(getKey(), destKey, keys);
+ }
+
+ @Override
+ public Set range(int start, int end) {
+ return ops.range(getKey(), start, end);
+ }
+
+ @Override
+ public Set rangeByScore(double min, double max) {
+ return ops.rangeByScore(getKey(), min, max);
+ }
+
+ @Override
+ public Integer rank(Object o) {
+ return ops.rank(getKey(), o);
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return ops.remove(getKey(), o);
+ }
+
+ @Override
+ public void removeRange(int start, int end) {
+ ops.removeRange(getKey(), start, end);
+ }
+
+ @Override
+ public void removeRangeByScore(double min, double max) {
+ ops.removeRangeByScore(getKey(), min, max);
+ }
+
+ @Override
+ public Set reverseRange(int start, int end) {
+ return ops.reverseRange(getKey(), start, end);
+ }
+
+ @Override
+ public int size() {
+ return ops.size(getKey());
+ }
+
+ @Override
+ public void unionAndStore(K destKey, K... keys) {
+ ops.unionAndStore(getKey(), destKey, keys);
+ }
+}
\ No newline at end of file
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultEntry.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java
similarity index 58%
rename from spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultEntry.java
rename to spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java
index db174291e..6c2dd57cc 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/DefaultEntry.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java
@@ -13,33 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.datastore.redis.connection;
+package org.springframework.datastore.redis.core;
-import org.springframework.datastore.redis.connection.RedisHashCommands.Entry;
/**
- * Default {@link Entry} implementation.
+ * Default {@link KeyBound} implementation.
*
* @author Costin Leau
*/
-public class DefaultEntry implements Entry {
+public class DefaultKeyBound implements KeyBound {
- private final String field;
- private final String value;
+ private final K key;
- public DefaultEntry(String field, String value) {
- this.field = field;
- this.value = value;
+ public DefaultKeyBound(K key) {
+ this.key = key;
}
@Override
- public String getField() {
- return null;
+ public K getKey() {
+ return key;
}
-
- @Override
- public String getValue() {
- return null;
- }
-
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java
new file mode 100644
index 000000000..29f336b7d
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.datastore.redis.core;
+
+/**
+ * Redis store for a certain key. Useful for creating views into Redis 'collection' types.
+ *
+ * @author Costin Leau
+ */
+public interface KeyBound {
+
+ /**
+ * Returns the key associated with this store.
+ *
+ * @return
+ */
+ K getKey();
+}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java
new file mode 100644
index 000000000..930466d6b
--- /dev/null
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.datastore.redis.core;
+
+import java.util.List;
+
+/**
+ * Redis, list specific operations.
+ *
+ * @author Costin Leau
+ */
+public interface ListOperations {
+
+ List range(K key, int start, int end);
+
+ void trim(K key, int start, int end);
+
+ Integer length(K key);
+
+ Integer leftPush(K key, V value);
+
+ Integer rightPush(K key, V value);
+
+ void set(K key, int index, V value);
+
+ Integer remove(K key, int i, Object value);
+
+ V index(K key, int index);
+
+ V leftPop(K key);
+
+ V rightPop(K key);
+
+ List blockingLeftPop(int timeout, K... keys);
+
+ List blockingRightPop(int timeout, K... keys);
+}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisConnectionUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisConnectionUtils.java
index bbaa8a88e..f5344e3f8 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisConnectionUtils.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisConnectionUtils.java
@@ -46,6 +46,10 @@ public abstract class RedisConnectionUtils {
if (connHolder != null)
return connHolder.getConnection();
+ if (!allowCreate) {
+ throw new IllegalArgumentException("No connection found and allowCreate = false");
+ }
+
if (log.isDebugEnabled())
log.debug("Opening RedisConnection");
@@ -56,10 +60,9 @@ public abstract class RedisConnectionUtils {
TransactionSynchronizationManager.registerSynchronization(new RedisConnectionSynchronization(connHolder,
factory, true));
TransactionSynchronizationManager.bindResource(factory, connHolder);
-
+ return connHolder.getConnection();
}
- return connHolder.getConnection();
-
+ return conn;
}
public static void releaseConnection(RedisConnection conn, RedisConnectionFactory factory) {
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java
index 7d6b8ea0e..52a4d5a89 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java
@@ -15,12 +15,39 @@
*/
package org.springframework.datastore.redis.core;
+
/**
* Basic set of Redis operations, implemented by {@link RedisTemplate}.
*
* @author Costin Leau
*/
-public interface RedisOperations {
+public interface RedisOperations {
+ void set(K key, V value);
+ V get(K key);
+
+ V getAndSet(K key, V newValue);
+
+ void watch(K... keys);
+
+ void multi();
+
+ Object exec();
+
+ Integer increment(K key, int delta);
+
+ void delete(K... keys);
+
+ ListOperations listOps();
+
+ BoundListOperations forList(K key);
+
+ SetOperations setOps();
+
+ BoundSetOperations forSet(K key);
+
+ ZSetOperations zSetOps();
+
+ BoundZSetOperations forZSet(K key);
}
diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java
index 3cfa23777..97db2af7e 100644
--- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java
+++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java
@@ -19,11 +19,17 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
import org.springframework.datastore.redis.connection.RedisConnection;
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
import org.springframework.datastore.redis.serializer.RedisSerializer;
import org.springframework.datastore.redis.serializer.SimpleRedisSerializer;
+import org.springframework.datastore.redis.serializer.StringRedisSerializer;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -43,10 +49,12 @@ import org.springframework.util.ClassUtils;
*
* @author Costin Leau
*/
-public class RedisTemplate extends RedisAccessor {
+public class RedisTemplate extends RedisAccessor implements RedisOperations {
private boolean exposeConnection = false;
- private RedisSerializer