diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
index 37d1f1049..7016d2cc1 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
@@ -15,8 +15,18 @@
*/
package org.springframework.data.redis.connection;
-import java.util.*;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Queue;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
@@ -1079,6 +1089,33 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return convertAndReturn(delegate.sort(key, params), identityConverter);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#encoding(byte[])
+ */
+ @Override
+ public ValueEncoding encodingOf(byte[] key) {
+ return convertAndReturn(delegate.encodingOf(key), identityConverter);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#idletime(byte[])
+ */
+ @Override
+ public Duration idletime(byte[] key) {
+ return convertAndReturn(delegate.idletime(key), identityConverter);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#refcount(byte[])
+ */
+ @Override
+ public Long refcount(byte[] key) {
+ return convertAndReturn(delegate.refcount(key), identityConverter);
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sPop(byte[])
@@ -1305,7 +1342,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return convertAndReturn(delegate.zIncrBy(key, increment, value), identityConverter);
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
*/
@@ -1566,7 +1603,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return convertAndReturn(delegate.zScore(key, value), identityConverter);
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
*/
@@ -2399,6 +2436,33 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return convertAndReturn(delegate.sort(serialize(key), params), byteListToStringList);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#encoding(java.lang.String)
+ */
+ @Override
+ public ValueEncoding encodingOf(String key) {
+ return encodingOf(serialize(key));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#idletime(java.lang.String)
+ */
+ @Override
+ public Duration idletime(String key) {
+ return idletime(serialize(key));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.StringRedisConnection#refcount(java.lang.String)
+ */
+ @Override
+ public Long refcount(String key) {
+ return refcount(serialize(key));
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#sPop(java.lang.String)
diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
index d40766594..b75aab1f2 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.connection;
+import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -223,6 +224,27 @@ public interface DefaultedRedisConnection extends RedisConnection {
return keyCommands().sort(key, params, sortKey);
}
+ /** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
+ @Override
+ @Deprecated
+ default ValueEncoding encodingOf(byte[] key) {
+ return keyCommands().encodingOf(key);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
+ @Override
+ @Deprecated
+ default Duration idletime(byte[] key) {
+ return keyCommands().idletime(key);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
+ @Override
+ @Deprecated
+ default Long refcount(byte[] key) {
+ return keyCommands().refcount(key);
+ }
+
// STRING COMMANDS
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java
index 8e0dd8771..182374eb9 100644
--- a/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java
@@ -692,4 +692,37 @@ public interface ReactiveKeyCommands {
* @see Redis Documentation: MOVE
*/
Flux> move(Publisher commands);
+
+ /**
+ * Get the type of internal representation used for storing the value at the given {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return the {@link Mono} emitting {@link org.springframework.data.redis.connection.ValueEncoding}.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT ENCODING
+ * @since 2.1
+ */
+ Mono encodingOf(ByteBuffer key);
+
+ /**
+ * Get the {@link Duration} since the object stored at the given {@code key} is idle.
+ *
+ * @param key must not be {@literal null}.
+ * @return the {@link Mono} emitting the idletime of the key of {@link Mono#empty()} if the key does not exist.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT IDLETIME
+ * @since 2.1
+ */
+ Mono idletime(ByteBuffer key);
+
+ /**
+ * Get the number of references of the value associated with the specified {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@link Mono#empty()} if key does not exist.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT REFCOUNT
+ * @since 2.1
+ */
+ Mono refcount(ByteBuffer key);
}
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java
index 27e364178..97ab4d09d 100644
--- a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java
@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.connection;
+import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -303,4 +304,42 @@ public interface RedisKeyCommands {
* @see Redis Documentation: RESTORE
*/
void restore(byte[] key, long ttlInMillis, byte[] serializedValue);
+
+ /**
+ * Get the type of internal representation used for storing the value at the given {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@link org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding#VACANT} if key does not
+ * exist or {@literal null} when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT ENCODING
+ * @since 2.1
+ */
+ @Nullable
+ ValueEncoding encodingOf(byte[] key);
+
+ /**
+ * Get the {@link Duration} since the object stored at the given {@code key} is idle.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@literal null} if key does not exist or when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT IDLETIME
+ * @since 2.1
+ */
+ @Nullable
+ Duration idletime(byte[] key);
+
+ /**
+ * Get the number of references of the value associated with the specified {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@literal null} if key does not exist or when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @see Redis Documentation: OBJECT REFCOUNT
+ * @since 2.1
+ */
+ @Nullable
+ Long refcount(byte[] key);
+
}
diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java
index 505716521..348c57d3e 100644
--- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java
@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.connection;
+import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -317,6 +318,39 @@ public interface StringRedisConnection extends RedisConnection {
*/
Long sort(String key, SortParameters params, String storeKey);
+ /**
+ * Get the type of internal representation used for storing the value at the given {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@literal null} if key does not exist or when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @since 2.1
+ */
+ @Nullable
+ ValueEncoding encodingOf(String key);
+
+ /**
+ * Get the {@link Duration} since the object stored at the given {@code key} is idle.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@literal null} if key does not exist or when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @since 2.1
+ */
+ @Nullable
+ Duration idletime(String key);
+
+ /**
+ * Get the number of references of the value associated with the specified {@code key}.
+ *
+ * @param key must not be {@literal null}.
+ * @return {@literal null} if key does not exist or when used in pipeline / transaction.
+ * @throws IllegalArgumentException if {@code key} is {@literal null}.
+ * @since 2.1
+ */
+ @Nullable
+ Long refcount(String key);
+
// -------------------------------------------------------------------------
// Methods dealing with values/Redis strings
// -------------------------------------------------------------------------
diff --git a/src/main/java/org/springframework/data/redis/connection/ValueEncoding.java b/src/main/java/org/springframework/data/redis/connection/ValueEncoding.java
new file mode 100644
index 000000000..ec8d418c9
--- /dev/null
+++ b/src/main/java/org/springframework/data/redis/connection/ValueEncoding.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2018 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.redis.connection;
+
+import java.util.Optional;
+
+import org.springframework.lang.Nullable;
+import org.springframework.util.ObjectUtils;
+
+/**
+ * {@link ValueEncoding} is used for the Redis internal data representation used in order to store the value associated
+ * with a key.
+ *
+ *
Strings
+ *
{@link RedisValueEncoding#RAW} or {@link RedisValueEncoding#INT}
+ *
Lists
+ *
{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#LINKEDLIST}
+ *
Sets
+ *
{@link RedisValueEncoding#INTSET} or {@link RedisValueEncoding#HASHTABLE}
+ *
Hashes
+ *
{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#HASHTABLE}
+ *
Sorted Sets
+ *
{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#SKIPLIST}