getOperations();
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java
new file mode 100644
index 000000000..d6791ea0f
--- /dev/null
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2010-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.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.data.keyvalue.redis.connection.DataType;
+
+/**
+ * Operations over a Redis key.
+ *
+ * Useful for executing common key-'bound' operations to all implementations.
+ *
+ * As the rest of the APIs, if the underlying connection is pipelined or queued/in multi mode,
+ * all methods will return null.
+ *
+ * @author Costin Leau
+ */
+public interface BoundKeyOperations {
+
+ /**
+ * Returns the key associated with this entity.
+ *
+ * @return key associated with the implementing entity
+ */
+ K getKey();
+
+ /**
+ * Returns the associated Redis type.
+ *
+ * @return key type
+ */
+ DataType getType();
+
+ /**
+ * Returns the expiration of this key.
+ *
+ * @return expiration value (in seconds)
+ */
+ Long getExpire();
+
+ /**
+ * Sets the key time-to-live/expiration.
+ *
+ * @param timeout expiration value
+ * @param unit expiration unit
+ * @return true if expiration was set, false otherwise
+ */
+ Boolean expire(long timeout, TimeUnit unit);
+
+ /**
+ * Sets the key time-to-live/expiration.
+ *
+ * @param date expiration date
+ * @return true if expiration was set, false otherwise
+ */
+ Boolean expireAt(Date date);
+
+ /**
+ * Removes the expiration (if any) of the key.
+ * @return true if expiration was removed, false otherwise
+ */
+ Boolean persist();
+
+ /**
+ * Renames the key.
+ *
+ * @param newKey new key
+ */
+ void rename(K newKey);
+}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java
index a51df518a..5701587ba 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java
@@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
*
* @author Costin Leau
*/
-public interface BoundListOperations extends KeyBound {
+public interface BoundListOperations extends BoundKeyOperations {
RedisOperations getOperations();
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java
index 2da61f806..e13520885 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java
@@ -24,7 +24,7 @@ import java.util.Set;
*
* @author Costin Leau
*/
-public interface BoundSetOperations extends KeyBound {
+public interface BoundSetOperations extends BoundKeyOperations {
RedisOperations getOperations();
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java
index ea7988ed2..ae6267bf9 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java
@@ -22,27 +22,27 @@ import java.util.concurrent.TimeUnit;
*
* @author Costin Leau
*/
-public interface BoundValueOperations extends KeyBound {
+public interface BoundValueOperations extends BoundKeyOperations {
RedisOperations getOperations();
void set(V value);
+ void set(V value, long offset);
+
void set(V value, long timeout, TimeUnit unit);
Boolean setIfAbsent(V value);
V get();
+ String get(long start, long end);
+
V getAndSet(V value);
Long increment(long delta);
Integer append(String value);
- String get(int start, int end);
-
- void set(int start, int end);
-
Long size();
}
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java
index 37222cc93..2ba5783d4 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java
@@ -25,7 +25,7 @@ import java.util.Set;
*
* @author Costin Leau
*/
-public interface BoundZSetOperations extends KeyBound {
+public interface BoundZSetOperations extends BoundKeyOperations {
RedisOperations getOperations();
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java
new file mode 100644
index 000000000..a44527cb4
--- /dev/null
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java
@@ -0,0 +1,64 @@
+/*
+ * 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.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.springframework.data.keyvalue.redis.connection.RedisConnection;
+
+/**
+* Invocation handler that suppresses close calls on {@link RedisConnection}.
+* @see RedisConnection#close()
+* @author Costin Leau
+*/
+class CloseSuppressingInvocationHandler implements InvocationHandler {
+
+ private static final String CLOSE = "close";
+ private static final String HASH_CODE = "hashCode";
+ private static final String EQUALS = "equals";
+
+ private final RedisConnection target;
+
+ public CloseSuppressingInvocationHandler(RedisConnection target) {
+ this.target = target;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+
+ if (method.getName().equals(EQUALS)) {
+ // Only consider equal when proxies are identical.
+ return (proxy == args[0]);
+ }
+ else if (method.getName().equals(HASH_CODE)) {
+ // Use hashCode of PersistenceManager proxy.
+ return System.identityHashCode(proxy);
+ }
+ else if (method.getName().equals(CLOSE)) {
+ // Handle close method: suppress, not valid.
+ return null;
+ }
+
+ // Invoke method on target RedisConnection.
+ try {
+ Object retVal = method.invoke(this.target, args);
+ return retVal;
+ } catch (InvocationTargetException ex) {
+ throw ex.getTargetException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java
index f55ed85be..c8e6a531e 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java
@@ -19,12 +19,14 @@ import java.util.Collection;
import java.util.Map;
import java.util.Set;
+import org.springframework.data.keyvalue.redis.connection.DataType;
+
/**
* Default implementation for {@link HashOperations}.
*
* @author Costin Leau
*/
-class DefaultBoundHashOperations extends DefaultKeyBound implements BoundHashOperations {
+class DefaultBoundHashOperations extends DefaultBoundKeyOperations implements BoundHashOperations {
private final HashOperations ops;
@@ -35,7 +37,7 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement
* @param template
*/
public DefaultBoundHashOperations(H key, RedisOperations operations) {
- super(key);
+ super(key, operations);
this.ops = operations.opsForHash();
}
@@ -103,4 +105,9 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement
public Map entries() {
return ops.entries(getKey());
}
+
+ @Override
+ public DataType getType() {
+ return DataType.HASH;
+ }
}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java
new file mode 100644
index 000000000..105c6e48b
--- /dev/null
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2010-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.Date;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * Default {@link BoundKeyOperations} implementation.
+ * Meant for internal usage.
+ *
+ * @author Costin Leau
+ */
+abstract class DefaultBoundKeyOperations implements BoundKeyOperations {
+
+ private K key;
+ private final RedisOperations ops;
+
+ public DefaultBoundKeyOperations(K key, RedisOperations operations) {
+ setKey(key);
+ this.ops = operations;
+ }
+
+ @Override
+ public K getKey() {
+ return key;
+ }
+
+ protected void setKey(K key) {
+ this.key = key;
+ }
+
+ @Override
+ public Boolean expire(long timeout, TimeUnit unit) {
+ return ops.expire(key, timeout, unit);
+ }
+
+ @Override
+ public Boolean expireAt(Date date) {
+ return ops.expireAt(key, date);
+ }
+
+ @Override
+ public Long getExpire() {
+ return ops.getExpire(key);
+ }
+
+ @Override
+ public Boolean persist() {
+ return ops.persist(key);
+ }
+
+ @Override
+ public void rename(K newKey) {
+ ops.rename(key, newKey);
+ key = newKey;
+ }
+}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java
index df302ad11..45a34511c 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java
@@ -18,13 +18,15 @@ package org.springframework.data.keyvalue.redis.core;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import org.springframework.data.keyvalue.redis.connection.DataType;
+
/**
* Default implementation for {@link BoundListOperations}.
*
* @author Costin Leau
*/
-class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations {
+class DefaultBoundListOperations extends DefaultBoundKeyOperations implements BoundListOperations {
private final ListOperations ops;
@@ -35,7 +37,7 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou
* @param operations
*/
public DefaultBoundListOperations(K key, RedisOperations operations) {
- super(key);
+ super(key, operations);
this.ops = operations.opsForList();
}
@@ -124,4 +126,9 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou
public void set(long index, V value) {
ops.set(getKey(), index, value);
}
+
+ @Override
+ public DataType getType() {
+ return DataType.LIST;
+ }
}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java
index e92e21bd2..d0010b63a 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java
@@ -19,12 +19,14 @@ package org.springframework.data.keyvalue.redis.core;
import java.util.Collection;
import java.util.Set;
+import org.springframework.data.keyvalue.redis.connection.DataType;
+
/**
* Default implementation for {@link BoundSetOperations}.
*
* @author Costin Leau
*/
-class DefaultBoundSetOperations extends DefaultKeyBound implements BoundSetOperations {
+class DefaultBoundSetOperations extends DefaultBoundKeyOperations implements BoundSetOperations {
private final SetOperations ops;
@@ -36,7 +38,7 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun
* @param operations
*/
DefaultBoundSetOperations(K key, RedisOperations operations) {
- super(key);
+ super(key, operations);
this.ops = operations.opsForSet();
}
@@ -146,4 +148,9 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun
public void unionAndStore(Collection keys, K destKey) {
ops.unionAndStore(getKey(), keys, destKey);
}
+
+ @Override
+ public DataType getType() {
+ return DataType.SET;
+ }
}
\ No newline at end of file
diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java
index 7d0b2322f..b9ec6b168 100644
--- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java
+++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java
@@ -17,10 +17,12 @@ package org.springframework.data.keyvalue.redis.core;
import java.util.concurrent.TimeUnit;
+import org.springframework.data.keyvalue.redis.connection.DataType;
+
/**
* @author Costin Leau
*/
-class DefaultBoundValueOperations extends DefaultKeyBound implements BoundValueOperations {
+class DefaultBoundValueOperations extends DefaultBoundKeyOperations implements BoundValueOperations {
private final ValueOperations ops;
@@ -31,7 +33,7 @@ class DefaultBoundValueOperations extends DefaultKeyBound implements Bo
* @param operations
*/
public DefaultBoundValueOperations(K key, RedisOperations operations) {
- super(key);
+ super(key, operations);
this.ops = operations.opsForValue();
}
@@ -56,7 +58,7 @@ class DefaultBoundValueOperations extends DefaultKeyBound implements Bo
}
@Override
- public String get(int start, int end) {
+ public String get(long start, long end) {
return ops.get(getKey(), start, end);
}
@@ -76,8 +78,8 @@ class DefaultBoundValueOperations