Merge branch 'master' into gradle-build
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
build
|
||||
.DS_Store
|
||||
target
|
||||
build
|
||||
.gradle
|
||||
.springBeans
|
||||
.ant-targets-build.xml
|
||||
|
||||
@@ -1,23 +1,50 @@
|
||||
SPRING DATA REDIS INTEGRATION CHANGELOG
|
||||
=======================================
|
||||
SPRING DATA KEY/VALUE INTEGRATION CHANGELOG
|
||||
===========================================
|
||||
http://www.springsource.org/spring-data
|
||||
|
||||
|
||||
Changes in version 1.0.0.M2 (2011-xx-yy)
|
||||
Changes in version 1.0.0.M2 (2011-02-10)
|
||||
----------------------------------------
|
||||
|
||||
Redis
|
||||
-----
|
||||
|
||||
General
|
||||
* Added PubSub support (message listener container and namespace)
|
||||
* Added JSON and Object/XML Mapping serializers
|
||||
* Completed support for Redis (2.2) commands
|
||||
* Improved documentation
|
||||
* Upgraded to Redis 2.2
|
||||
* Updraded to Jedis 1.5.1
|
||||
* Updraded to Jedis 1.5.2
|
||||
|
||||
Package o.s.d.k.redis.connection
|
||||
* Added sort support
|
||||
* Added pipelining support
|
||||
* Added StringRedisConnection for String-focused operations
|
||||
* Renamed JedisConnectionFactory pooling to usePool
|
||||
* Renamed JredisConnectionFactory pooling to usePool
|
||||
|
||||
Package o.s.d.k.redis.connection.jedis
|
||||
* Added support for Jedis rich exceptions
|
||||
* Added support for broken pooled connection
|
||||
|
||||
Package o.s.d.k.redis.core
|
||||
* Fix serializationg bug for hash value inside RedisTemplate
|
||||
* Added injection for Redis operations ("views")
|
||||
|
||||
Package o.s.d.k.redis.support
|
||||
* Refined AtomicInteger and AtomicLong constructors to use the backing store value as initial counter
|
||||
|
||||
|
||||
Riak
|
||||
----
|
||||
|
||||
General
|
||||
* Important bug fixes
|
||||
* Fully asynchronous AsyncRiakTemplate object
|
||||
* Groovy DSL for Riak access using async template underneath
|
||||
|
||||
|
||||
Changes in version Riak 1.0.0.M1 (2010-12-15)
|
||||
---------------------------------------------
|
||||
General
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SPRING DATASTORE KEY-VALUE 1.0.0 ${version}
|
||||
-------------------------------------------
|
||||
SPRING DATASTORE KEY-VALUE 1.0.0 M2 (2010 02 10)
|
||||
------------------------------------------------
|
||||
|
||||
Spring Datastore Key-Value is released under the terms of the Apache Software License Version 2.0 (see license.txt).
|
||||
|
||||
@@ -14,4 +14,4 @@ The reference manual and javadoc are located in the 'docs' directory.
|
||||
ADDITIONAL RESOURCES:
|
||||
|
||||
Spring Data Homepage: http://www.springsource.org/spring-data
|
||||
Spring Data Forum: http://forum.springsource.org/forumdisplay.php?f=80
|
||||
Spring Data Forum : http://forum.springsource.org/forumdisplay.php?f=80
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation for {@link SortParameters}.
|
||||
@@ -25,7 +29,7 @@ public class DefaultSortParameters implements SortParameters {
|
||||
|
||||
private byte[] byPattern;
|
||||
private Range limit;
|
||||
private byte[] getPattern;
|
||||
private final List<byte[]> getPattern = new ArrayList<byte[]>(4);
|
||||
private Order order;
|
||||
private Boolean alphabetic;
|
||||
|
||||
@@ -56,13 +60,13 @@ public class DefaultSortParameters implements SortParameters {
|
||||
* @param order
|
||||
* @param alphabetic
|
||||
*/
|
||||
public DefaultSortParameters(byte[] byPattern, Range limit, byte[] getPattern, Order order, Boolean alphabetic) {
|
||||
public DefaultSortParameters(byte[] byPattern, Range limit, byte[][] getPattern, Order order, Boolean alphabetic) {
|
||||
super();
|
||||
this.byPattern = byPattern;
|
||||
this.limit = limit;
|
||||
this.getPattern = getPattern;
|
||||
this.order = order;
|
||||
this.alphabetic = alphabetic;
|
||||
setGetPattern(getPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,12 +88,20 @@ public class DefaultSortParameters implements SortParameters {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getGetPattern() {
|
||||
return getPattern;
|
||||
public byte[][] getGetPattern() {
|
||||
return getPattern.toArray(new byte[getPattern.size()][]);
|
||||
}
|
||||
|
||||
public void setGetPattern(byte[] getPattern) {
|
||||
this.getPattern = getPattern;
|
||||
public void addGetPattern(byte[] gPattern) {
|
||||
getPattern.add(gPattern);
|
||||
}
|
||||
|
||||
public void setGetPattern(byte[][] gPattern) {
|
||||
getPattern.clear();
|
||||
|
||||
for (byte[] bs : gPattern) {
|
||||
getPattern.add(bs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +142,7 @@ public class DefaultSortParameters implements SortParameters {
|
||||
}
|
||||
|
||||
public SortParameters get(byte[] pattern) {
|
||||
setGetPattern(pattern);
|
||||
addGetPattern(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ public interface RedisListCommands {
|
||||
|
||||
Long lLen(byte[] key);
|
||||
|
||||
List<byte[]> lRange(byte[] key, long start, long end);
|
||||
List<byte[]> lRange(byte[] key, long begin, long end);
|
||||
|
||||
void lTrim(byte[] key, long start, long end);
|
||||
void lTrim(byte[] key, long begin, long end);
|
||||
|
||||
byte[] lIndex(byte[] key, long index);
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ public interface RedisPubSubCommands {
|
||||
* or not.
|
||||
*
|
||||
* @return true if the connection is subscribed, false otherwise
|
||||
* @see #subscribe(MessageListener, byte[]...)
|
||||
* @see #pSubscribe(MessageListener, byte[]...)
|
||||
*/
|
||||
boolean isSubscribed();
|
||||
|
||||
@@ -37,8 +35,6 @@ public interface RedisPubSubCommands {
|
||||
* not subscribed.
|
||||
*
|
||||
* @return the current subscription, null if none is available
|
||||
* @see #subscribe(listener, channels)
|
||||
* @see #pSubscribe(listener, channels)
|
||||
*/
|
||||
Subscription getSubscription();
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ public interface RedisStringCommands {
|
||||
|
||||
Long append(byte[] key, byte[] value);
|
||||
|
||||
byte[] getRange(byte[] key, int start, int end);
|
||||
byte[] getRange(byte[] key, int begin, int end);
|
||||
|
||||
void setRange(byte[] key, int start, int end);
|
||||
void setRange(byte[] key, int begin, int end);
|
||||
|
||||
Boolean getBit(byte[] key, long offset);
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ public interface RedisZSetCommands {
|
||||
|
||||
Long zRevRank(byte[] key, byte[] value);
|
||||
|
||||
Set<byte[]> zRange(byte[] key, long start, long end);
|
||||
Set<byte[]> zRange(byte[] key, long begin, long end);
|
||||
|
||||
Set<Tuple> zRangeWithScore(byte[] key, long start, long end);
|
||||
Set<Tuple> zRangeWithScore(byte[] key, long begin, long end);
|
||||
|
||||
Set<byte[]> zRevRange(byte[] key, long start, long end);
|
||||
Set<byte[]> zRevRange(byte[] key, long begin, long end);
|
||||
|
||||
Set<Tuple> zRevRangeWithScore(byte[] key, long start, long end);
|
||||
Set<Tuple> zRevRangeWithScore(byte[] key, long begin, long end);
|
||||
|
||||
Set<byte[]> zRangeByScore(byte[] key, double min, double max);
|
||||
|
||||
@@ -74,7 +74,7 @@ public interface RedisZSetCommands {
|
||||
|
||||
Double zScore(byte[] key, byte[] value);
|
||||
|
||||
Long zRemRange(byte[] key, long start, long end);
|
||||
Long zRemRange(byte[] key, long begin, long end);
|
||||
|
||||
Long zRemRangeByScore(byte[] key, double min, double max);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public interface SortParameters {
|
||||
*
|
||||
* @return <tt>GET</tt> pattern.
|
||||
*/
|
||||
byte[] getGetPattern();
|
||||
byte[][] getGetPattern();
|
||||
|
||||
/**
|
||||
* Returns the sorting limit (range or pagination).
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -87,7 +87,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
*/
|
||||
protected Jedis fetchJedisConnector() {
|
||||
try {
|
||||
if (usePool) {
|
||||
if (usePool && pool != null) {
|
||||
return pool.getResource();
|
||||
}
|
||||
Jedis jedis = new Jedis(getShardInfo());
|
||||
|
||||
@@ -161,7 +161,7 @@ public abstract class JedisUtils {
|
||||
jedisParams.by(params.getByPattern());
|
||||
}
|
||||
|
||||
byte[] getPattern = params.getGetPattern();
|
||||
byte[][] getPattern = params.getGetPattern();
|
||||
if (getPattern != null) {
|
||||
jedisParams.get(getPattern);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jredis.ClientRuntimeException;
|
||||
import org.jredis.JRedis;
|
||||
import org.jredis.RedisException;
|
||||
import org.jredis.Sort;
|
||||
@@ -62,11 +63,16 @@ public class JredisConnection implements RedisConnection {
|
||||
this.isPool = (jredis instanceof JRedisService);
|
||||
}
|
||||
|
||||
protected DataAccessException convertJedisAccessException(Exception ex) {
|
||||
protected DataAccessException convertJredisAccessException(Exception ex) {
|
||||
if (ex instanceof RedisException) {
|
||||
return JredisUtils.convertJredisAccessException((RedisException) ex);
|
||||
}
|
||||
throw new UncategorizedKeyvalueStoreException("Unknown JRedis exception", ex);
|
||||
|
||||
if (ex instanceof ClientRuntimeException) {
|
||||
return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex);
|
||||
}
|
||||
|
||||
return new UncategorizedKeyvalueStoreException("Unknown JRedis exception", ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,8 +122,8 @@ public class JredisConnection implements RedisConnection {
|
||||
JredisUtils.applySortingParams(sort, params, null);
|
||||
try {
|
||||
return sort.exec();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +133,8 @@ public class JredisConnection implements RedisConnection {
|
||||
JredisUtils.applySortingParams(sort, params, null);
|
||||
try {
|
||||
return Support.unpackValue(sort.exec());
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +142,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long dbSize() {
|
||||
try {
|
||||
return jredis.dbsize();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,8 +151,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void flushDb() {
|
||||
try {
|
||||
jredis.flushdb();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +160,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void flushAll() {
|
||||
try {
|
||||
jredis.flushall();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,8 +169,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
return jredis.echo(message);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +179,8 @@ public class JredisConnection implements RedisConnection {
|
||||
try {
|
||||
jredis.ping();
|
||||
return "PONG";
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +188,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void bgSave() {
|
||||
try {
|
||||
jredis.bgsave();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,8 +197,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void bgWriteAof() {
|
||||
try {
|
||||
jredis.bgrewriteaof();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +206,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void save() {
|
||||
try {
|
||||
jredis.save();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,8 +220,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Properties info() {
|
||||
try {
|
||||
return JredisUtils.info(jredis.info());
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +229,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long lastSave() {
|
||||
try {
|
||||
return jredis.lastsave();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +253,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long del(byte[]... keys) {
|
||||
try {
|
||||
return jredis.del(JredisUtils.decodeMultiple(keys));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,8 +262,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void discard() {
|
||||
try {
|
||||
jredis.discard();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,8 +276,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean exists(byte[] key) {
|
||||
try {
|
||||
return jredis.exists(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,8 +285,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean expire(byte[] key, long seconds) {
|
||||
try {
|
||||
return jredis.expire(JredisUtils.decode(key), (int) seconds);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,8 +294,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean expireAt(byte[] key, long unixTime) {
|
||||
try {
|
||||
return jredis.expireat(JredisUtils.decode(key), unixTime);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,8 +303,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Collection<byte[]> keys(byte[] pattern) {
|
||||
try {
|
||||
return JredisUtils.convertCollection(jredis.keys(JredisUtils.decode(pattern)));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,8 +322,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] randomKey() {
|
||||
try {
|
||||
return JredisUtils.encode(jredis.randomkey());
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,8 +331,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void rename(byte[] oldName, byte[] newName) {
|
||||
try {
|
||||
jredis.rename(JredisUtils.decode(oldName), JredisUtils.decode(newName));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,8 +340,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean renameNX(byte[] oldName, byte[] newName) {
|
||||
try {
|
||||
return jredis.renamenx(JredisUtils.decode(oldName), JredisUtils.decode(newName));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,8 +354,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long ttl(byte[] key) {
|
||||
try {
|
||||
return jredis.ttl(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,8 +363,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public DataType type(byte[] key) {
|
||||
try {
|
||||
return JredisUtils.convertDataType(jredis.type(JredisUtils.decode(key)));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,8 +386,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] get(byte[] key) {
|
||||
try {
|
||||
return jredis.get(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,8 +395,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void set(byte[] key, byte[] value) {
|
||||
try {
|
||||
jredis.set(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,8 +404,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] getSet(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.getset(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,8 +413,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long append(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.append(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,8 +422,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public List<byte[]> mGet(byte[]... keys) {
|
||||
try {
|
||||
return jredis.mget(JredisUtils.decodeMultiple(keys));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,8 +431,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void mSet(Map<byte[], byte[]> tuple) {
|
||||
try {
|
||||
jredis.mset(JredisUtils.decodeMap(tuple));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,8 +440,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void mSetNX(Map<byte[], byte[]> tuple) {
|
||||
try {
|
||||
jredis.msetnx(JredisUtils.decodeMap(tuple));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,8 +454,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean setNX(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.setnx(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +463,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] getRange(byte[] key, int start, int end) {
|
||||
try {
|
||||
return jredis.substr(JredisUtils.decode(key), start, end);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,8 +472,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long decr(byte[] key) {
|
||||
try {
|
||||
return jredis.decr(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,8 +481,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long decrBy(byte[] key, long value) {
|
||||
try {
|
||||
return jredis.decrby(JredisUtils.decode(key), (int) value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,8 +490,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long incr(byte[] key) {
|
||||
try {
|
||||
return jredis.incr(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,8 +499,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long incrBy(byte[] key, long value) {
|
||||
try {
|
||||
return jredis.incrby(JredisUtils.decode(key), (int) value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,8 +542,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] lIndex(byte[] key, long index) {
|
||||
try {
|
||||
return jredis.lindex(JredisUtils.decode(key), index);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,8 +551,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long lLen(byte[] key) {
|
||||
try {
|
||||
return jredis.llen(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,8 +560,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] lPop(byte[] key) {
|
||||
try {
|
||||
return jredis.lpop(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,8 +570,8 @@ public class JredisConnection implements RedisConnection {
|
||||
try {
|
||||
jredis.lpush(JredisUtils.decode(key), value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,8 +581,8 @@ public class JredisConnection implements RedisConnection {
|
||||
List<byte[]> lrange = jredis.lrange(JredisUtils.decode(key), start, end);
|
||||
|
||||
return lrange;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,8 +590,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long lRem(byte[] key, long count, byte[] value) {
|
||||
try {
|
||||
return jredis.lrem(JredisUtils.decode(key), value, (int) count);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,8 +599,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void lSet(byte[] key, long index, byte[] value) {
|
||||
try {
|
||||
jredis.lset(JredisUtils.decode(key), index, value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,8 +608,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public void lTrim(byte[] key, long start, long end) {
|
||||
try {
|
||||
jredis.ltrim(JredisUtils.decode(key), start, end);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,8 +617,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] rPop(byte[] key) {
|
||||
try {
|
||||
return jredis.rpop(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,8 +626,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
|
||||
try {
|
||||
return jredis.rpoplpush(JredisUtils.decode(srcKey), JredisUtils.decode(dstKey));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,8 +636,8 @@ public class JredisConnection implements RedisConnection {
|
||||
try {
|
||||
jredis.rpush(JredisUtils.decode(key), value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,8 +670,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean sAdd(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.sadd(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,8 +679,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long sCard(byte[] key) {
|
||||
try {
|
||||
return jredis.scard(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,8 +692,8 @@ public class JredisConnection implements RedisConnection {
|
||||
try {
|
||||
List<byte[]> result = jredis.sdiff(destKey, sets);
|
||||
return new LinkedHashSet<byte[]>(result);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,8 +704,8 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
try {
|
||||
jredis.sdiffstore(destSet, sets);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,8 +717,8 @@ public class JredisConnection implements RedisConnection {
|
||||
try {
|
||||
List<byte[]> result = jredis.sinter(set1, sets);
|
||||
return new LinkedHashSet<byte[]>(result);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,8 +729,8 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
try {
|
||||
jredis.sinterstore(destSet, sets);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,8 +738,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean sIsMember(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.sismember(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,8 +747,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Set<byte[]> sMembers(byte[] key) {
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(jredis.smembers(JredisUtils.decode(key)));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,8 +756,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
|
||||
try {
|
||||
return jredis.smove(JredisUtils.decode(srcKey), JredisUtils.decode(destKey), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,8 +765,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] sPop(byte[] key) {
|
||||
try {
|
||||
return jredis.spop(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,8 +774,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] sRandMember(byte[] key) {
|
||||
try {
|
||||
return jredis.srandmember(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,8 +783,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean sRem(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.srem(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,8 +795,8 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(jredis.sunion(set1, sets));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,8 +807,8 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
try {
|
||||
jredis.sunionstore(destSet, sets);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -815,8 +821,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean zAdd(byte[] key, double score, byte[] value) {
|
||||
try {
|
||||
return jredis.zadd(JredisUtils.decode(key), score, value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,8 +830,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zCard(byte[] key) {
|
||||
try {
|
||||
return jredis.zcard(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,8 +839,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zCount(byte[] key, double min, double max) {
|
||||
try {
|
||||
return jredis.zcount(JredisUtils.decode(key), min, max);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -842,8 +848,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Double zIncrBy(byte[] key, double increment, byte[] value) {
|
||||
try {
|
||||
return jredis.zincrby(JredisUtils.decode(key), increment, value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,8 +867,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Set<byte[]> zRange(byte[] key, long start, long end) {
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(jredis.zrange(JredisUtils.decode(key), start, end));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,8 +882,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Set<byte[]> zRangeByScore(byte[] key, double min, double max) {
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(jredis.zrangebyscore(JredisUtils.decode(key), min, max));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -900,8 +906,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zRank(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.zrank(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,8 +915,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean zRem(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.zrem(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,8 +924,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zRemRange(byte[] key, long start, long end) {
|
||||
try {
|
||||
return jredis.zremrangebyrank(JredisUtils.decode(key), start, end);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,8 +933,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zRemRangeByScore(byte[] key, double min, double max) {
|
||||
try {
|
||||
return jredis.zremrangebyscore(JredisUtils.decode(key), min, max);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,8 +942,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Set<byte[]> zRevRange(byte[] key, long start, long end) {
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(jredis.zrevrange(JredisUtils.decode(key), start, end));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,8 +956,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long zRevRank(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.zrevrank(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -959,8 +965,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Double zScore(byte[] key, byte[] value) {
|
||||
try {
|
||||
return jredis.zscore(JredisUtils.decode(key), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -983,8 +989,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean hDel(byte[] key, byte[] field) {
|
||||
try {
|
||||
return jredis.hdel(JredisUtils.decode(key), JredisUtils.decode(field));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -992,8 +998,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean hExists(byte[] key, byte[] field) {
|
||||
try {
|
||||
return jredis.hexists(JredisUtils.decode(key), JredisUtils.decode(field));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1001,8 +1007,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public byte[] hGet(byte[] key, byte[] field) {
|
||||
try {
|
||||
return jredis.hget(JredisUtils.decode(key), JredisUtils.decode(field));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,8 +1016,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Map<byte[], byte[]> hGetAll(byte[] key) {
|
||||
try {
|
||||
return JredisUtils.encodeMap(jredis.hgetall(JredisUtils.decode(key)));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1024,8 +1030,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Set<byte[]> hKeys(byte[] key) {
|
||||
try {
|
||||
return new LinkedHashSet<byte[]>(JredisUtils.convertCollection(jredis.hkeys(JredisUtils.decode(key))));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1033,8 +1039,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Long hLen(byte[] key) {
|
||||
try {
|
||||
return jredis.hlen(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,8 +1058,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public Boolean hSet(byte[] key, byte[] field, byte[] value) {
|
||||
try {
|
||||
return jredis.hset(JredisUtils.decode(key), JredisUtils.decode(field), value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1066,8 +1072,8 @@ public class JredisConnection implements RedisConnection {
|
||||
public List<byte[]> hVals(byte[] key) {
|
||||
try {
|
||||
return jredis.hvals(JredisUtils.decode(key));
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.connection.jredis;
|
||||
|
||||
import org.jredis.ClientRuntimeException;
|
||||
import org.jredis.connector.Connection;
|
||||
import org.jredis.connector.ConnectionSpec;
|
||||
import org.jredis.connector.Connection.Socket.Property;
|
||||
@@ -74,8 +75,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
|
||||
public void afterPropertiesSet() {
|
||||
if (connectionSpec == null) {
|
||||
Assert.hasText(hostName);
|
||||
connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, DEFAULT_REDIS_DB,
|
||||
DEFAULT_REDIS_PASSWORD);
|
||||
connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, DEFAULT_REDIS_DB, DEFAULT_REDIS_PASSWORD);
|
||||
connectionSpec.setConnectionFlag(Connection.Flag.RELIABLE, false);
|
||||
|
||||
if (StringUtils.hasLength(password)) {
|
||||
@@ -111,6 +111,9 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean
|
||||
|
||||
@Override
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
if (ex instanceof ClientRuntimeException) {
|
||||
return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,13 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jredis.ClientRuntimeException;
|
||||
import org.jredis.RedisException;
|
||||
import org.jredis.RedisType;
|
||||
import org.jredis.Sort;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
@@ -49,6 +51,16 @@ public abstract class JredisUtils {
|
||||
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given, native JRedis exception to Spring's DAO hierarchy.
|
||||
*
|
||||
* @param ex JRedis exception
|
||||
* @return converted exception
|
||||
*/
|
||||
public static DataAccessException convertJredisAccessException(ClientRuntimeException ex) {
|
||||
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
static DataType convertDataType(RedisType type) {
|
||||
switch (type) {
|
||||
case NONE:
|
||||
@@ -117,9 +129,12 @@ public abstract class JredisUtils {
|
||||
if (byPattern != null) {
|
||||
jredisSort.BY(decode(byPattern));
|
||||
}
|
||||
byte[] getPattern = params.getGetPattern();
|
||||
if (getPattern != null) {
|
||||
jredisSort.GET(decode(getPattern));
|
||||
byte[][] getPattern = params.getGetPattern();
|
||||
|
||||
if (getPattern != null && getPattern.length > 0) {
|
||||
for (byte[] bs : getPattern) {
|
||||
jredisSort.GET(decode(bs));
|
||||
}
|
||||
}
|
||||
Range limit = params.getLimit();
|
||||
if (limit != null) {
|
||||
|
||||
@@ -28,17 +28,29 @@ public interface BoundSetOperations<K, V> extends KeyBound<K> {
|
||||
|
||||
RedisOperations<K, V> getOperations();
|
||||
|
||||
Set<V> diff(K key);
|
||||
|
||||
Set<V> diff(Collection<K> keys);
|
||||
|
||||
void diffAndStore(K destKey, Collection<K> keys);
|
||||
void diffAndStore(K key, K destKey);
|
||||
|
||||
void diffAndStore(Collection<K> keys, K destKey);
|
||||
|
||||
Set<V> intersect(K key);
|
||||
|
||||
Set<V> intersect(Collection<K> keys);
|
||||
|
||||
void intersectAndStore(K destKey, Collection<K> keys);
|
||||
void intersectAndStore(K key, K destKey);
|
||||
|
||||
void intersectAndStore(Collection<K> keys, K destKey);
|
||||
|
||||
Set<V> union(K key);
|
||||
|
||||
Set<V> union(Collection<K> keys);
|
||||
|
||||
void unionAndStore(K destKey, Collection<K> keys);
|
||||
void unionAndStore(K key, K destKey);
|
||||
|
||||
void unionAndStore(Collection<K> keys, K destKey);
|
||||
|
||||
Boolean add(V value);
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ public interface BoundZSetOperations<K, V> extends KeyBound<K> {
|
||||
|
||||
RedisOperations<K, V> getOperations();
|
||||
|
||||
void intersectAndStore(K destKey, Collection<K> keys);
|
||||
void intersectAndStore(K otherKey, K destKey);
|
||||
|
||||
void intersectAndStore(Collection<K> otherKeys, K destKey);
|
||||
|
||||
Set<V> range(long start, long end);
|
||||
|
||||
@@ -41,7 +43,9 @@ public interface BoundZSetOperations<K, V> extends KeyBound<K> {
|
||||
|
||||
void removeRangeByScore(double min, double max);
|
||||
|
||||
void unionAndStore(K destKey, Collection<K> keys);
|
||||
void unionAndStore(K otherKey, K destKey);
|
||||
|
||||
void unionAndStore(Collection<K> otherKeys, K destKey);
|
||||
|
||||
Boolean add(V value, double score);
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mapper translating Redis bulk value responses (typically returned by a sort query) to actual objects. Implementations of this interface do not have to worry
|
||||
* about exception or connection handling.
|
||||
* <p/>
|
||||
* Typically used by {@link RedisTemplate} <tt>sort</tt> methods.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface BulkMapper<T, V> {
|
||||
|
||||
T mapBulk(List<V> tuple);
|
||||
}
|
||||
@@ -45,14 +45,25 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
return ops.add(getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> diff(K key) {
|
||||
return ops.difference(getKey(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> diff(Collection<K> keys) {
|
||||
return ops.difference(getKey(), keys);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void diffAndStore(K destKey, Collection<K> keys) {
|
||||
ops.differenceAndStore(getKey(), destKey, keys);
|
||||
public void diffAndStore(K key, K destKey) {
|
||||
ops.differenceAndStore(getKey(), key, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void diffAndStore(Collection<K> keys, K destKey) {
|
||||
ops.differenceAndStore(getKey(), keys, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,14 +71,24 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
return ops.getOperations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> intersect(K key) {
|
||||
return ops.intersect(getKey(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> intersect(Collection<K> keys) {
|
||||
return ops.intersect(getKey(), keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K destKey, Collection<K> keys) {
|
||||
ops.intersectAndStore(getKey(), destKey, keys);
|
||||
public void intersectAndStore(K key, K destKey) {
|
||||
ops.intersectAndStore(getKey(), key, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(Collection<K> keys, K destKey) {
|
||||
ops.intersectAndStore(getKey(), keys, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +103,7 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
|
||||
@Override
|
||||
public Boolean move(K destKey, V value) {
|
||||
return ops.move(getKey(), destKey, value);
|
||||
return ops.move(getKey(), value, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,13 +126,24 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
return ops.size(getKey());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<V> union(K key) {
|
||||
return ops.union(getKey(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> union(Collection<K> keys) {
|
||||
return ops.union(getKey(), keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K destKey, Collection<K> keys) {
|
||||
ops.unionAndStore(getKey(), destKey, keys);
|
||||
public void unionAndStore(K key, K destKey) {
|
||||
ops.unionAndStore(getKey(), key, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(Collection<K> keys, K destKey) {
|
||||
ops.unionAndStore(getKey(), keys, destKey);
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,13 @@ class DefaultBoundZSetOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K destKey, Collection<K> keys) {
|
||||
ops.intersectAndStore(getKey(), destKey, keys);
|
||||
public void intersectAndStore(K destKey, K otherKey) {
|
||||
ops.intersectAndStore(getKey(), otherKey, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(Collection<K> otherKeys, K destKey) {
|
||||
ops.intersectAndStore(getKey(), otherKeys, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +120,12 @@ class DefaultBoundZSetOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K destKey, Collection<K> keys) {
|
||||
ops.unionAndStore(getKey(), destKey, keys);
|
||||
public void unionAndStore(K otherKey, K destKey) {
|
||||
ops.unionAndStore(getKey(), otherKey, destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(Collection<K> otherKeys, K destKey) {
|
||||
ops.unionAndStore(getKey(), otherKeys, destKey);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,8 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.core.query.SortQuery;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,8 @@ public interface RedisOperations<K, V> {
|
||||
|
||||
Boolean hasKey(K key);
|
||||
|
||||
void delete(K key);
|
||||
|
||||
void delete(Collection<K> key);
|
||||
|
||||
DataType type(K key);
|
||||
@@ -85,6 +88,8 @@ public interface RedisOperations<K, V> {
|
||||
|
||||
Long getExpire(K key);
|
||||
|
||||
void watch(K keys);
|
||||
|
||||
void watch(Collection<K> keys);
|
||||
|
||||
void unwatch();
|
||||
@@ -98,10 +103,6 @@ public interface RedisOperations<K, V> {
|
||||
|
||||
Object exec();
|
||||
|
||||
List<V> sort(K key, SortParameters params);
|
||||
|
||||
Long sort(K key, SortParameters params, K destination);
|
||||
|
||||
// pubsub functionality on the template
|
||||
void convertAndSend(String destination, Object message);
|
||||
|
||||
@@ -187,4 +188,17 @@ public interface RedisOperations<K, V> {
|
||||
* @return hash operations bound to the given key.
|
||||
*/
|
||||
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);
|
||||
|
||||
|
||||
List<V> sort(SortQuery<K> query);
|
||||
|
||||
|
||||
<T> List<T> sort(SortQuery<K> query, RedisSerializer<T> resultSerializer);
|
||||
|
||||
|
||||
<T> List<T> sort(SortQuery<K> query, BulkMapper<T, V> bulkMapper);
|
||||
|
||||
<T, S> List<T> sort(SortQuery<K> query, BulkMapper<T, S> bulkMapper, RedisSerializer<S> resultSerializer);
|
||||
|
||||
Long sort(SortQuery<K> query, K storeKey);
|
||||
}
|
||||
@@ -32,10 +32,12 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.DefaultSortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.keyvalue.redis.core.query.SortQuery;
|
||||
import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||
@@ -145,7 +147,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
* @return object returned by the action
|
||||
*/
|
||||
public <T> T execute(RedisCallback<T> action, boolean exposeConnection) {
|
||||
return execute(action, exposeConnection, valueSerializer);
|
||||
return execute(action, exposeConnection, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,35 +160,6 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
* @return object returned by the action
|
||||
*/
|
||||
public <T> T execute(RedisCallback<T> action, boolean exposeConnection, boolean pipeline) {
|
||||
return execute(action, exposeConnection, pipeline, valueSerializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given action object within a connection, which can be exposed or not. Allows a custom serializer
|
||||
* to be specified for the returned object.
|
||||
*
|
||||
* @param <T> return type
|
||||
* @param action action callback object that specifies the Redis action
|
||||
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
|
||||
* @param returnSerializer serializer used for converting the binary data to the custom return type
|
||||
* @return returned by the action
|
||||
*/
|
||||
public <T> T execute(RedisCallback<T> action, boolean exposeConnection, RedisSerializer<?> returnSerializer) {
|
||||
return execute(action, exposeConnection, false, returnSerializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given action object within a connection, which can be exposed or not. Allows a custom serializer
|
||||
* to be specified for the returned object.
|
||||
*
|
||||
* @param <T> return type
|
||||
* @param action action callback object that specifies the Redis action
|
||||
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
|
||||
* @param pipeline whether to pipeline or not the connection for the execution duration
|
||||
* @param returnSerializer serializer used for converting the binary data to the custom return type
|
||||
* @return returned by the action
|
||||
*/
|
||||
public <T> T execute(RedisCallback<T> action, boolean exposeConnection, boolean pipeline, RedisSerializer<?> returnSerializer) {
|
||||
Assert.notNull(action, "Callback object must not be null");
|
||||
|
||||
RedisConnectionFactory factory = getConnectionFactory();
|
||||
@@ -203,7 +176,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
try {
|
||||
RedisConnection connToExpose = (exposeConnection ? conn : createRedisConnectionProxy(conn));
|
||||
T result = action.doInRedis(connToExpose);
|
||||
// TODO: should do flush?
|
||||
// TODO: any other connection processing?
|
||||
return postProcessResult(result, conn, existingConnection);
|
||||
} finally {
|
||||
try {
|
||||
@@ -426,6 +399,15 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
return rawKeys;
|
||||
}
|
||||
|
||||
private byte[][] rawKeys(K key, K otherKey) {
|
||||
final byte[][] rawKeys = new byte[2][];
|
||||
|
||||
|
||||
rawKeys[0] = rawKey(key);
|
||||
rawKeys[1] = rawKey(key);
|
||||
return rawKeys;
|
||||
}
|
||||
|
||||
private byte[][] rawKeys(K key, Collection<K> keys) {
|
||||
final byte[][] rawKeys = new byte[keys.size() + 1][];
|
||||
|
||||
@@ -441,11 +423,16 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Collection<V>> T deserializeValues(Collection<byte[]> rawValues, Class<? extends Collection> type) {
|
||||
Collection<V> values = (List.class.isAssignableFrom(type) ? new ArrayList<V>(rawValues.size())
|
||||
: new LinkedHashSet<V>(rawValues.size()));
|
||||
return (T) deserializeValues(rawValues, type, valueSerializer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Collection<?>> T deserializeValues(Collection<byte[]> rawValues, Class<? extends Collection> type, RedisSerializer<?> redisSerializer) {
|
||||
Collection<Object> values = (List.class.isAssignableFrom(type) ? new ArrayList<Object>(rawValues.size())
|
||||
: new LinkedHashSet<Object>(rawValues.size()));
|
||||
for (byte[] bs : rawValues) {
|
||||
if (bs != null) {
|
||||
values.add((V) valueSerializer.deserialize(bs));
|
||||
values.add(redisSerializer.deserialize(bs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,6 +562,19 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(K key) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) {
|
||||
connection.del(rawKey);
|
||||
return null;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(keys);
|
||||
@@ -626,33 +626,6 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> sort(K key, final SortParameters params) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() {
|
||||
@Override
|
||||
public List<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.sort(rawKey, params);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues, List.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sort(K key, final SortParameters params, K destination) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawDestKey = rawKey(destination);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.sort(rawKey, params, rawDestKey);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertAndSend(String channel, Object message) {
|
||||
Assert.hasText(channel, "a non-empty channel is required");
|
||||
@@ -787,6 +760,19 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(K key) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) {
|
||||
connection.watch(rawKey);
|
||||
return null;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(keys);
|
||||
@@ -1301,8 +1287,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> difference(final K key, final Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public Set<V> difference(K key, K otherKey) {
|
||||
return difference(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> difference(final K key, final Collection<K> otherKeys) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
@@ -1314,8 +1305,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void differenceAndStore(final K key, K destKey, final Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public void differenceAndStore(K key, K otherKey, K destKey) {
|
||||
differenceAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void differenceAndStore(final K key, final Collection<K> otherKeys, K destKey) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
@@ -1332,8 +1328,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> intersect(K key, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public Set<V> intersect(K key, K otherKey) {
|
||||
return intersect(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> intersect(K key, Collection<K> otherKeys) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
@@ -1345,8 +1346,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K key, K destKey, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public void intersectAndStore(K key, K otherKey, K destKey) {
|
||||
intersectAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
@@ -1383,7 +1389,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean move(K key, K destKey, V value) {
|
||||
public Boolean move(K key, V value, K destKey) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
@@ -1441,8 +1447,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> union(K key, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public Set<V> union(K key, K otherKey) {
|
||||
return union(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> union(K key, Collection<K> otherKeys) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
@@ -1454,8 +1465,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K key, K destKey, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public void unionAndStore(K key, K otherKey, K destKey) {
|
||||
unionAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
@@ -1514,9 +1530,15 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
return RedisTemplate.this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K key, K destKey, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public void intersectAndStore(K key, K otherKey, K destKey) {
|
||||
intersectAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
@@ -1672,8 +1694,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K key, K destKey, Collection<K> keys) {
|
||||
final byte[][] rawKeys = rawKeys(key, keys);
|
||||
public void unionAndStore(K key, K otherKey, K destKey) {
|
||||
unionAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unionAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
final byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
final byte[] rawDestKey = rawKey(destKey);
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
@@ -1899,4 +1926,89 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
return deserializeHashMap(entries);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort operations
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<V> sort(SortQuery<K> query) {
|
||||
return sort(query, valueSerializer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> List<T> sort(SortQuery<K> query, RedisSerializer<T> resultSerializer) {
|
||||
final byte[] rawKey = rawKey(query.getKey());
|
||||
final SortParameters params = convertQuery(query, stringSerializer);
|
||||
|
||||
List<byte[]> vals = execute(new RedisCallback<List<byte[]>>() {
|
||||
@Override
|
||||
public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.sort(rawKey, params);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return (List<T>) deserializeValues(vals, List.class, resultSerializer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> List<T> sort(SortQuery<K> query, BulkMapper<T, V> bulkMapper) {
|
||||
return sort(query, bulkMapper, valueSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, S> List<T> sort(SortQuery<K> query, BulkMapper<T, S> bulkMapper, RedisSerializer<S> resultSerializer) {
|
||||
List<S> values = sort(query, resultSerializer);
|
||||
|
||||
int bulkSize = query.getGetPattern().size();
|
||||
List<T> result = new ArrayList<T>(values.size() / bulkSize + 1);
|
||||
|
||||
List<S> bulk = new ArrayList<S>(bulkSize);
|
||||
for (S s : values) {
|
||||
|
||||
bulk.add(s);
|
||||
if (bulk.size() == bulkSize) {
|
||||
result.add(bulkMapper.mapBulk(Collections.unmodifiableList(bulk)));
|
||||
// create a new list (we could reuse the old one but the client might hang on to it for some reason)
|
||||
bulk = new ArrayList<S>(bulkSize);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sort(SortQuery<K> query, K storeKey) {
|
||||
final byte[] rawStoreKey = rawKey(storeKey);
|
||||
final byte[] rawKey = rawKey(query.getKey());
|
||||
final SortParameters params = convertQuery(query, stringSerializer);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.sort(rawKey, params, rawStoreKey);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
private static <K> SortParameters convertQuery(SortQuery<K> query, RedisSerializer<String> stringSerializer) {
|
||||
|
||||
return new DefaultSortParameters(stringSerializer.serialize(query.getBy()), query.getLimit(), serialize(
|
||||
query.getGetPattern(), stringSerializer), query.getOrder(), query.isAlphabetic());
|
||||
}
|
||||
|
||||
private static byte[][] serialize(List<String> strings, RedisSerializer<String> stringSerializer) {
|
||||
List<byte[]> raw = null;
|
||||
|
||||
if (strings == null) {
|
||||
raw = Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
raw = new ArrayList<byte[]>(strings.size());
|
||||
for (String key : strings) {
|
||||
raw.add(stringSerializer.serialize(key));
|
||||
}
|
||||
}
|
||||
return raw.toArray(new byte[raw.size()][]);
|
||||
}
|
||||
}
|
||||
@@ -26,17 +26,29 @@ import java.util.Set;
|
||||
*/
|
||||
public interface SetOperations<K, V> {
|
||||
|
||||
Set<V> difference(K key, Collection<K> keys);
|
||||
Set<V> difference(K key, K otherKey);
|
||||
|
||||
void differenceAndStore(K key, K destKey, Collection<K> keys);
|
||||
Set<V> difference(K key, Collection<K> otherKeys);
|
||||
|
||||
Set<V> intersect(K key, Collection<K> keys);
|
||||
void differenceAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void intersectAndStore(K key, K destKey, Collection<K> keys);
|
||||
void differenceAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
Set<V> union(K key, Collection<K> keys);
|
||||
Set<V> intersect(K key, K otherKey);
|
||||
|
||||
void unionAndStore(K key, K destKey, Collection<K> keys);
|
||||
Set<V> intersect(K key, Collection<K> otherKeys);
|
||||
|
||||
void intersectAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void intersectAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
Set<V> union(K key, K otherKey);
|
||||
|
||||
Set<V> union(K key, Collection<K> otherKeys);
|
||||
|
||||
void unionAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void unionAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
Boolean add(K key, V value);
|
||||
|
||||
@@ -44,7 +56,7 @@ public interface SetOperations<K, V> {
|
||||
|
||||
Set<V> members(K key);
|
||||
|
||||
Boolean move(K key, K destKey, V value);
|
||||
Boolean move(K key, V value, K destKey);
|
||||
|
||||
V randomMember(K key);
|
||||
|
||||
|
||||
@@ -26,9 +26,13 @@ import java.util.Set;
|
||||
*/
|
||||
public interface ZSetOperations<K, V> {
|
||||
|
||||
void intersectAndStore(K key, K destKey, Collection<K> keys);
|
||||
void intersectAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void unionAndStore(K key, K destKey, Collection<K> keys);
|
||||
void intersectAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
void unionAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void unionAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
Set<V> range(K key, long start, long end);
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link SortCriterion}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class DefaultSortCriterion<K> implements SortCriterion<K> {
|
||||
|
||||
private final K key;
|
||||
private String by;
|
||||
private final List<String> getKeys = new ArrayList<String>(4);
|
||||
|
||||
private Range limit;
|
||||
private Order order;
|
||||
private Boolean alpha;
|
||||
|
||||
DefaultSortCriterion(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortCriterion<K> alphabetical(boolean alpha) {
|
||||
this.alpha = Boolean.valueOf(alpha);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortQuery<K> build() {
|
||||
return new DefaultSortQuery<K>(key, by, limit, order, alpha, getKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortCriterion<K> limit(long offset, long count) {
|
||||
this.limit = new Range(offset, count);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortCriterion<K> limit(Range range) {
|
||||
this.limit = range;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortCriterion<K> order(Order order) {
|
||||
this.order = order;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortCriterion<K> get(String getPattern) {
|
||||
this.getKeys.add(getPattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
SortCriterion<K> addBy(String keyPattern) {
|
||||
this.by = keyPattern;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
|
||||
/**
|
||||
* Default SortQuery implementation.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class DefaultSortQuery<K> implements SortQuery<K> {
|
||||
|
||||
private final K key;
|
||||
private final Boolean alpha;
|
||||
private final Order order;
|
||||
private final Range limit;
|
||||
private final String by;
|
||||
private final List<String> gets;
|
||||
|
||||
DefaultSortQuery(K key, String by, Range limit, Order order, Boolean alpha, List<String> gets) {
|
||||
this.key = key;
|
||||
this.by = by;
|
||||
this.limit = limit;
|
||||
this.order = order;
|
||||
this.alpha = alpha;
|
||||
this.gets = gets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBy() {
|
||||
return by;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isAlphabetic() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGetPattern() {
|
||||
return gets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultSortQuery [alpha=" + alpha + ", by=" + by + ", gets=" + gets + ", key=" + key + ", limit="
|
||||
+ limit + ", order=" + order + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core.query;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
|
||||
/**
|
||||
* Internal interface part of the Sort DSL. Exposes generic operations.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface SortCriterion<K> {
|
||||
|
||||
SortCriterion<K> limit(long offset, long count);
|
||||
|
||||
SortCriterion<K> limit(Range range);
|
||||
|
||||
SortCriterion<K> order(Order order);
|
||||
|
||||
SortCriterion<K> alphabetical(boolean alpha);
|
||||
|
||||
SortCriterion<K> get(String pattern);
|
||||
|
||||
SortQuery<K> build();
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* High-level abstraction over a Redis SORT (generified equivalent of {@link SortParameters}). To be used with {@link RedisTemplate}
|
||||
* (just as {@link SortParameters} is used by {@link RedisConnection}).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface SortQuery<K> {
|
||||
|
||||
/**
|
||||
* Returns the sorting order. Can be null if nothing is specified.
|
||||
*
|
||||
* @return sorting order
|
||||
*/
|
||||
Order getOrder();
|
||||
|
||||
/**
|
||||
* Indicates if the sorting is numeric (default) or alphabetical (lexicographical).
|
||||
* Can be null if nothing is specified.
|
||||
*
|
||||
* @return the type of sorting
|
||||
*/
|
||||
Boolean isAlphabetic();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the sorting limit (range or pagination).
|
||||
* Can be null if nothing is specified.
|
||||
*
|
||||
* @return sorting limit/range
|
||||
*/
|
||||
Range getLimit();
|
||||
|
||||
/**
|
||||
* Return the target key for sorting.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
K getKey();
|
||||
|
||||
/**
|
||||
* Returns the pattern of the external key used for sorting.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getBy();
|
||||
|
||||
/**
|
||||
* Returns the external key(s) whose values are returned by the sort.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<String> getGetPattern();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core.query;
|
||||
|
||||
|
||||
/**
|
||||
* Simple builder class for constructing {@link SortQuery}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class SortQueryBuilder<K> extends DefaultSortCriterion<K> {
|
||||
|
||||
private static final String NO_SORT_KEY = "~";
|
||||
|
||||
private SortQueryBuilder(K key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
public static <K> SortQueryBuilder<K> sort(K key) {
|
||||
return new SortQueryBuilder<K>(key);
|
||||
}
|
||||
|
||||
public SortCriterion<K> by(String keyPattern) {
|
||||
return addBy(keyPattern);
|
||||
}
|
||||
|
||||
public SortCriterion<K> noSort() {
|
||||
return by(NO_SORT_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.hash;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
|
||||
/**
|
||||
* HashMapper based on Apache Commons BeanUtils project. Does NOT supports nested properties.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class BeanUtilsHashMapper<T> implements HashMapper<T, String, String> {
|
||||
|
||||
private Class<T> type;
|
||||
|
||||
public BeanUtilsHashMapper(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromHash(Map<String, String> hash) {
|
||||
T instance = org.springframework.beans.BeanUtils.instantiate(type);
|
||||
try {
|
||||
BeanUtils.populate(instance, hash);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> toHash(T object) {
|
||||
try {
|
||||
return BeanUtils.describe(object);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Cannot describe object " + object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.hash;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Delegating hash mapper used for flattening objects into Strings.
|
||||
* Suitable when dealing with mappers that support Strings and type conversion.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DecoratingStringHashMapper<T> implements HashMapper<T, String, String> {
|
||||
|
||||
private final HashMapper<T, ?, ?> delegate;
|
||||
|
||||
public <K, V> DecoratingStringHashMapper(HashMapper<T, K, V> mapper) {
|
||||
this.delegate = mapper;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T fromHash(Map<String, String> hash) {
|
||||
Map h = hash;
|
||||
return delegate.fromHash(h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> toHash(T object) {
|
||||
Map<?, ?> hash = delegate.toHash(object);
|
||||
Map<String, String> flatten = new LinkedHashMap<String, String>(hash.size());
|
||||
for (Map.Entry<?, ?> entry : hash.entrySet()) {
|
||||
flatten.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
|
||||
}
|
||||
return flatten;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.hash;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Core mapping contract between Java types and Redis hashes/maps.
|
||||
* It's up to the implementation to support nested objects.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface HashMapper<T, K, V> {
|
||||
|
||||
Map<K, V> toHash(T object);
|
||||
|
||||
T fromHash(Map<K, V> hash);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.hash;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.map.type.TypeFactory;
|
||||
import org.codehaus.jackson.type.JavaType;
|
||||
|
||||
/**
|
||||
* Mapper based on Jackson library. Supports nested properties (rich objects).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class JacksonHashMapper<T> implements HashMapper<T, String, Object> {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
private final JavaType userType;
|
||||
private final JavaType mapType = TypeFactory.type(Map.class);
|
||||
|
||||
public JacksonHashMapper(Class<T> type) {
|
||||
this(type, new ObjectMapper());
|
||||
}
|
||||
|
||||
public JacksonHashMapper(Class<T> type, ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
this.userType = TypeFactory.type(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T fromHash(Map<String, Object> hash) {
|
||||
return (T) mapper.convertValue(hash, userType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> toHash(T object) {
|
||||
return mapper.convertValue(object, mapType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.serializer;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple toString() serializer for the core (lang) numberic JDK types.
|
||||
*
|
||||
* @see String#valueOf(Object)
|
||||
* @see Long#valueOf(String)
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class BasicNumberToStringSerializer<T extends Number> implements RedisSerializer<T> {
|
||||
|
||||
private final Charset charset;
|
||||
private final Constructor<T> ctor;
|
||||
|
||||
public BasicNumberToStringSerializer(Class<T> type) {
|
||||
this(type, Charset.forName("UTF8"));
|
||||
}
|
||||
|
||||
public BasicNumberToStringSerializer(Class<T> type, Charset charset) {
|
||||
Assert.notNull(type);
|
||||
this.charset = charset;
|
||||
|
||||
if (!(Byte.class.isAssignableFrom(type) || Short.class.isAssignableFrom(type)
|
||||
|| Long.class.isAssignableFrom(type) || Integer.class.isAssignableFrom(type)
|
||||
|| Float.class.isAssignableFrom(type) || Double.class.isAssignableFrom(type))) {
|
||||
throw new IllegalArgumentException("Type " + type + " not supported");
|
||||
}
|
||||
|
||||
try {
|
||||
ctor = type.getConstructor(String.class);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Cannot find suitable constructor for " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(byte[] bytes) {
|
||||
String string = new String(bytes, charset);
|
||||
return BeanUtils.instantiateClass(ctor, string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(T object) {
|
||||
String string = String.valueOf(object);
|
||||
return string.getBytes(charset);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class GenericToStringSerializer<T> implements RedisSerializer<T>, BeanFac
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
if (converter != null && beanFactory instanceof ConfigurableBeanFactory) {
|
||||
if (converter == null && beanFactory instanceof ConfigurableBeanFactory) {
|
||||
ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory;
|
||||
ConversionService conversionService = cFB.getConversionService();
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.redis.support.atomic;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.KeyBound;
|
||||
@@ -25,6 +24,8 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.core.SessionCallback;
|
||||
import org.springframework.data.keyvalue.redis.core.ValueOperations;
|
||||
import org.springframework.data.keyvalue.redis.serializer.BasicNumberToStringSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Atomic integer backed by Redis.
|
||||
@@ -48,6 +49,8 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
*/
|
||||
public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Integer> redisTemplate = new RedisTemplate<String, Integer>(factory);
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new BasicNumberToStringSerializer<Integer>(Integer.class));
|
||||
redisTemplate.setExposeConnection(true);
|
||||
this.key = redisCounter;
|
||||
this.generalOps = redisTemplate;
|
||||
@@ -172,18 +175,11 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
|
||||
/**
|
||||
* Atomically increment by one the current value.
|
||||
*
|
||||
* @return the previous value
|
||||
*/
|
||||
public int getAndIncrement() {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
int value = get();
|
||||
generalOps.multi();
|
||||
operations.increment(key, 1);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return incrementAndGet() - 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,15 +188,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
* @return the previous value
|
||||
*/
|
||||
public int getAndDecrement() {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
int value = get();
|
||||
generalOps.multi();
|
||||
operations.increment(key, -1);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return decrementAndGet() + 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,15 +198,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
* @return the previous value
|
||||
*/
|
||||
public int getAndAdd(final int delta) {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
int value = get();
|
||||
generalOps.multi();
|
||||
set(value + delta);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return addAndGet(delta) - delta;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.redis.support.atomic;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.KeyBound;
|
||||
@@ -25,6 +24,8 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.core.SessionCallback;
|
||||
import org.springframework.data.keyvalue.redis.core.ValueOperations;
|
||||
import org.springframework.data.keyvalue.redis.serializer.BasicNumberToStringSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Atomic long backed by Redis.
|
||||
@@ -48,6 +49,8 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
*/
|
||||
public RedisAtomicLong(String redisCounter, RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Long> redisTemplate = new RedisTemplate<String, Long>(factory);
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new BasicNumberToStringSerializer<Long>(Long.class));
|
||||
redisTemplate.setExposeConnection(true);
|
||||
this.key = redisCounter;
|
||||
this.generalOps = redisTemplate;
|
||||
@@ -177,15 +180,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
* @return the previous value
|
||||
*/
|
||||
public long getAndIncrement() {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
long value = get();
|
||||
generalOps.multi();
|
||||
operations.increment(key, 1);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return incrementAndGet() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,15 +189,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
* @return the previous value
|
||||
*/
|
||||
public long getAndDecrement() {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
long value = get();
|
||||
generalOps.multi();
|
||||
operations.increment(key, -11);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return decrementAndGet() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,15 +199,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
* @return the previous value
|
||||
*/
|
||||
public long getAndAdd(final long delta) {
|
||||
return CASUtils.execute(generalOps, key, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
long value = get();
|
||||
generalOps.multi();
|
||||
set(value + delta);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return addAndGet(delta) - delta;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,36 +66,71 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
|
||||
this.boundSetOps = boundOps;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<E> diff(RedisSet<?> set) {
|
||||
return boundSetOps.diff(set.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> diff(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.diff(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RedisSet<E> diffAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.diffAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
public RedisSet<E> diffAndStore(RedisSet<?> set, String destKey) {
|
||||
boundSetOps.diffAndStore(set.getKey(), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> diffAndStore(Collection<? extends RedisSet<?>> sets, String destKey) {
|
||||
boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> intersect(RedisSet<?> set) {
|
||||
return boundSetOps.intersect(set.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> intersect(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.intersect(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> intersectAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.intersectAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
public RedisSet<E> intersectAndStore(RedisSet<?> set, String destKey) {
|
||||
boundSetOps.intersectAndStore(set.getKey(), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> intersectAndStore(Collection<? extends RedisSet<?>> sets, String destKey) {
|
||||
boundSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> union(RedisSet<?> set) {
|
||||
return boundSetOps.union(set.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> union(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.union(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> unionAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.unionAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
public RedisSet<E> unionAndStore(RedisSet<?> set, String destKey) {
|
||||
boundSetOps.unionAndStore(set.getKey(), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> unionAndStore(Collection<? extends RedisSet<?>> sets, String destKey) {
|
||||
boundSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey);
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().boundSetOps(destKey));
|
||||
}
|
||||
|
||||
@@ -109,7 +144,7 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
|
||||
// intersect the set with a non existing one
|
||||
// TODO: find a safer way to clean the set
|
||||
String randomKey = UUID.randomUUID().toString();
|
||||
boundSetOps.intersectAndStore(getKey(), Collections.singleton(randomKey));
|
||||
boundSetOps.intersectAndStore(Collections.singleton(randomKey), getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,8 +91,14 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> intersectAndStore(String destKey, Collection<? extends RedisZSet<?>> sets) {
|
||||
boundZSetOps.intersectAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
public RedisZSet<E> intersectAndStore(RedisZSet<?> set, String destKey) {
|
||||
boundZSetOps.intersectAndStore(set.getKey(), destKey);
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> intersectAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) {
|
||||
boundZSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey);
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
@@ -124,8 +130,14 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> unionAndStore(String destKey, Collection<? extends RedisZSet<?>> sets) {
|
||||
boundZSetOps.unionAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
public RedisZSet<E> unionAndStore(RedisZSet<?> set, String destKey) {
|
||||
boundZSetOps.unionAndStore(set.getKey(), destKey);
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) {
|
||||
boundZSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey);
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.concurrent.BlockingDeque;
|
||||
*/
|
||||
public interface RedisList<E> extends RedisCollection<E>, List<E>, BlockingDeque<E> {
|
||||
|
||||
List<E> range(long start, long end);
|
||||
List<E> range(long begin, long end);
|
||||
|
||||
RedisList<E> trim(int start, int end);
|
||||
RedisList<E> trim(int begin, int end);
|
||||
}
|
||||
|
||||
@@ -26,15 +26,27 @@ import java.util.Set;
|
||||
*/
|
||||
public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
|
||||
|
||||
Set<E> intersect(RedisSet<?> set);
|
||||
|
||||
Set<E> intersect(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
Set<E> union(RedisSet<?> set);
|
||||
|
||||
Set<E> union(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
Set<E> diff(RedisSet<?> set);
|
||||
|
||||
Set<E> diff(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
RedisSet<E> intersectAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
RedisSet<E> intersectAndStore(RedisSet<?> set, String destKey);
|
||||
|
||||
RedisSet<E> unionAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
RedisSet<E> intersectAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
|
||||
|
||||
RedisSet<E> diffAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
RedisSet<E> unionAndStore(RedisSet<?> set, String destKey);
|
||||
|
||||
RedisSet<E> unionAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
|
||||
|
||||
RedisSet<E> diffAndStore(RedisSet<?> set, String destKey);
|
||||
|
||||
RedisSet<E> diffAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,13 @@ import java.util.SortedSet;
|
||||
*/
|
||||
public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
|
||||
RedisZSet<E> intersectAndStore(String destKey, Collection<? extends RedisZSet<?>> sets);
|
||||
RedisZSet<E> intersectAndStore(RedisZSet<?> set, String destKey);
|
||||
|
||||
RedisZSet<E> unionAndStore(String destKey, Collection<? extends RedisZSet<?>> sets);
|
||||
RedisZSet<E> intersectAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
|
||||
|
||||
RedisZSet<E> unionAndStore(RedisZSet<?> set, String destKey);
|
||||
|
||||
RedisZSet<E> unionAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
|
||||
|
||||
Set<E> range(long start, long end);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.UUID;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.keyvalue.redis.Address;
|
||||
import org.springframework.data.keyvalue.redis.Person;
|
||||
import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer;
|
||||
@@ -32,15 +33,16 @@ import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||
|
||||
public abstract class AbstractConnectionIntegrationTests {
|
||||
|
||||
protected RedisConnection connection;
|
||||
protected StringRedisConnection connection;
|
||||
protected RedisSerializer serializer = new JdkSerializationRedisSerializer();
|
||||
protected RedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
|
||||
private static final String listName = "test-list";
|
||||
private static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
connection = getConnectionFactory().getConnection();
|
||||
connection = new DefaultStringRedisConnection(getConnectionFactory().getConnection());
|
||||
}
|
||||
|
||||
protected abstract RedisConnectionFactory getConnectionFactory();
|
||||
@@ -97,4 +99,45 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertNotNull(version);
|
||||
System.out.println(info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullKey() throws Exception {
|
||||
connection.decr((String) null);
|
||||
connection.decr(EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullValue() throws Exception {
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
connection.append(key, EMPTY_ARRAY);
|
||||
try {
|
||||
connection.append(key, null);
|
||||
} catch (DataAccessException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashNullKey() throws Exception {
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
connection.hExists(key, EMPTY_ARRAY);
|
||||
try {
|
||||
connection.hExists(key, null);
|
||||
} catch (DataAccessException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashNullValue() throws Exception {
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
byte[] field = "random".getBytes();
|
||||
|
||||
connection.hSet(key, field, EMPTY_ARRAY);
|
||||
try {
|
||||
connection.hSet(key, field, null);
|
||||
} catch (DataAccessException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.core;
|
||||
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.springframework.data.keyvalue.redis.core.query.SortQueryBuilder;
|
||||
|
||||
public class SortTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testBasicDSL() throws Exception {
|
||||
SortQueryBuilder.sort("list").build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.Address;
|
||||
import org.springframework.data.keyvalue.redis.Person;
|
||||
import org.springframework.data.keyvalue.redis.hash.HashMapper;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public abstract class AbstractHashMapperTest {
|
||||
protected abstract HashMapper mapperFor(Class t);
|
||||
|
||||
private void test(Object o) {
|
||||
HashMapper<Object, Object, Object> mapper = mapperFor(o.getClass());
|
||||
Map hash = mapper.toHash(o);
|
||||
System.out.println("object hash " + hash.size() + " is " + hash);
|
||||
assertEquals(o, mapper.fromHash(hash));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleBean() throws Exception {
|
||||
test(new Address("Broadway", 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedBean() throws Exception {
|
||||
test(new Person("George", "Enescu", 74, new Address("liveni", 19)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.mapping;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.hash.BeanUtilsHashMapper;
|
||||
import org.springframework.data.keyvalue.redis.hash.HashMapper;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class BeanUtilsHashMapperTest extends AbstractHashMapperTest {
|
||||
|
||||
@Override
|
||||
protected HashMapper mapperFor(Class t) {
|
||||
return new BeanUtilsHashMapper(t);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNestedBean() throws Exception {
|
||||
super.testNestedBean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2011 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.data.keyvalue.redis.mapping;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.hash.HashMapper;
|
||||
import org.springframework.data.keyvalue.redis.hash.JacksonHashMapper;
|
||||
|
||||
public class JacksonHashMapperTest extends AbstractHashMapperTest {
|
||||
|
||||
@Override
|
||||
protected HashMapper mapperFor(Class t) {
|
||||
return new JacksonHashMapper(t);
|
||||
}
|
||||
}
|
||||
@@ -78,4 +78,30 @@ public class RedisAtomicTests {
|
||||
assertTrue(longCounter.compareAndSet(0, 10));
|
||||
assertTrue(longCounter.compareAndSet(10, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongIncrement() throws Exception {
|
||||
longCounter.set(0);
|
||||
assertEquals(1, longCounter.incrementAndGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntIncrement() throws Exception {
|
||||
intCounter.set(0);
|
||||
assertEquals(1, intCounter.incrementAndGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongCustomIncrement() throws Exception {
|
||||
longCounter.set(0);
|
||||
long delta = 5;
|
||||
assertEquals(delta, longCounter.addAndGet(delta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntCustomIncrement() throws Exception {
|
||||
intCounter.set(0);
|
||||
int delta = 5;
|
||||
assertEquals(delta, intCounter.addAndGet(delta));
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
diffSet2.add(t4);
|
||||
|
||||
String resultName = "test:set:diff:result:1";
|
||||
RedisSet<T> diff = set.diffAndStore(resultName, Arrays.asList(diffSet1, diffSet2));
|
||||
RedisSet<T> diff = set.diffAndStore(Arrays.asList(diffSet1, diffSet2), resultName);
|
||||
|
||||
assertEquals(1, diff.size());
|
||||
assertThat(diff, hasItem(t1));
|
||||
@@ -153,7 +153,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
intSet2.add(t3);
|
||||
|
||||
String resultName = "test:set:intersect:result:1";
|
||||
RedisSet<T> inter = set.intersectAndStore(resultName, Arrays.asList(intSet1, intSet2));
|
||||
RedisSet<T> inter = set.intersectAndStore(Arrays.asList(intSet1, intSet2), resultName);
|
||||
assertEquals(1, inter.size());
|
||||
assertThat(inter, hasItem(t2));
|
||||
assertEquals(resultName, inter.getKey());
|
||||
@@ -199,7 +199,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
unionSet2.add(t3);
|
||||
|
||||
String resultName = "test:set:union:result:1";
|
||||
RedisSet<T> union = set.unionAndStore(resultName, Arrays.asList(unionSet1, unionSet2));
|
||||
RedisSet<T> union = set.unionAndStore(Arrays.asList(unionSet1, unionSet2), resultName);
|
||||
assertEquals(4, union.size());
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
assertEquals(resultName, union.getKey());
|
||||
|
||||
@@ -207,7 +207,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
interSet2.add(t3, 3);
|
||||
|
||||
String resultName = "test:zset:inter:result:1";
|
||||
RedisZSet<T> inter = zSet.intersectAndStore(resultName, Arrays.asList(interSet1, interSet2));
|
||||
RedisZSet<T> inter = zSet.intersectAndStore(Arrays.asList(interSet1, interSet2), resultName);
|
||||
|
||||
assertEquals(1, inter.size());
|
||||
assertThat(inter, hasItem(t2));
|
||||
@@ -327,7 +327,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
unionSet2.add(t3, 6);
|
||||
|
||||
String resultName = "test:zset:union:result:1";
|
||||
RedisZSet<T> union = zSet.unionAndStore(resultName, Arrays.asList(unionSet1, unionSet2));
|
||||
RedisZSet<T> union = zSet.unionAndStore(Arrays.asList(unionSet1, unionSet2), resultName);
|
||||
assertEquals(4, union.size());
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
assertEquals(resultName, union.getKey());
|
||||
|
||||
@@ -23,4 +23,6 @@ Import-Template:
|
||||
redis.clients.jedis.*;version="[1.5.2, 2.0.0)",
|
||||
redis.clients.util.*;version="[1.5.2, 2.0.0)",
|
||||
org.apache.commons.pool.impl.*;version="[1.0.0, 3.0.0)",
|
||||
org.codehaus.jackson.*;version="[1.6, 2.0.0)"
|
||||
org.codehaus.jackson.*;version="[1.6, 2.0.0)",
|
||||
org.apache.commons.beanutils.*;version="[1.8.0, 2.0.0)"
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>spring-datastore-keyvalue-parent</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Reference in New Issue
Block a user