DATAREDIS-716 - Add support for OBJECT REFCOUNT, ENCODING and IDLETIME.
Original pull request: #337.
This commit is contained in:
committed by
Mark Paluch
parent
f8d63f4736
commit
70a3e5dbe7
@@ -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)
|
||||
|
||||
@@ -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()}}. */
|
||||
|
||||
@@ -692,4 +692,37 @@ public interface ReactiveKeyCommands {
|
||||
* @see <a href="http://redis.io/commands/move">Redis Documentation: MOVE</a>
|
||||
*/
|
||||
Flux<BooleanResponse<MoveCommand>> move(Publisher<MoveCommand> 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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT ENCODING</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
Mono<ValueEncoding> 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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT IDLETIME</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
Mono<Duration> 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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT REFCOUNT</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
Mono<Long> refcount(ByteBuffer key);
|
||||
}
|
||||
|
||||
@@ -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 <a href="http://redis.io/commands/restore">Redis Documentation: RESTORE</a>
|
||||
*/
|
||||
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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT ENCODING</a>
|
||||
* @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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT IDLETIME</a>
|
||||
* @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 <a href="http://redis.io/commands/object">Redis Documentation: OBJECT REFCOUNT</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
@Nullable
|
||||
Long refcount(byte[] key);
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -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. <br />
|
||||
* <dl>
|
||||
* <dt>Strings</dt>
|
||||
* <dd>{@link RedisValueEncoding#RAW} or {@link RedisValueEncoding#INT}</dd>
|
||||
* <dt>Lists</dt>
|
||||
* <dd>{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#LINKEDLIST}</dd>
|
||||
* <dt>Sets</dt>
|
||||
* <dd>{@link RedisValueEncoding#INTSET} or {@link RedisValueEncoding#HASHTABLE}</dd>
|
||||
* <dt>Hashes</dt>
|
||||
* <dd>{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#HASHTABLE}</dd>
|
||||
* <dt>Sorted Sets</dt>
|
||||
* <dd>{@link RedisValueEncoding#ZIPLIST} or {@link RedisValueEncoding#SKIPLIST}</dd>
|
||||
* <dt>Absent keys</dt>
|
||||
* <dd>{@link RedisValueEncoding#VACANT}</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface ValueEncoding {
|
||||
|
||||
@Nullable
|
||||
String raw();
|
||||
|
||||
/**
|
||||
* Get the {@link ValueEncoding} for given {@code encoding}.
|
||||
*
|
||||
* @param encoding can be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
static ValueEncoding of(@Nullable String encoding) {
|
||||
return RedisValueEncoding.lookup(encoding).orElse(() -> encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default {@link ValueEncoding} implementation of encodings used in Redis.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
enum RedisValueEncoding implements ValueEncoding {
|
||||
|
||||
/**
|
||||
* Normal string encoding.
|
||||
*/
|
||||
RAW("raw"), //
|
||||
/**
|
||||
* 64 bit signed interval String representing an integer.
|
||||
*/
|
||||
INT("int"), //
|
||||
/**
|
||||
* Space saving representation for small lists, hashes and sorted sets.
|
||||
*/
|
||||
ZIPLIST("ziplist"), //
|
||||
/**
|
||||
* Encoding for large lists.
|
||||
*/
|
||||
LINKEDLIST("linkedlist"), //
|
||||
/**
|
||||
* Space saving representation for small sets that contain only integers.ø
|
||||
*/
|
||||
INTSET("intset"), //
|
||||
/**
|
||||
* Encoding for large hashes.
|
||||
*/
|
||||
HASHTABLE("hashtable"), //
|
||||
/**
|
||||
* Encoding for sorted sets of any size.
|
||||
*/
|
||||
SKIPLIST("skiplist"), //
|
||||
/**
|
||||
* No encoding present due to non existing key.
|
||||
*/
|
||||
VACANT(null);
|
||||
|
||||
private final @Nullable String raw;
|
||||
|
||||
RedisValueEncoding(@Nullable String raw) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Optional<ValueEncoding> lookup(@Nullable String encoding) {
|
||||
|
||||
for (ValueEncoding valueEncoding : values()) {
|
||||
if (ObjectUtils.nullSafeEquals(valueEncoding.raw(), encoding)) {
|
||||
return Optional.of(valueEncoding);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -424,6 +425,19 @@ abstract public class Converters {
|
||||
return (Converter) MAP_TO_PROPERTIES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given {@literal nullable seconds} to a {@link Duration} or {@literal null}.
|
||||
*
|
||||
* @param seconds can be {@literal null}.
|
||||
* @return given {@literal seconds} as {@link Duration} or {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
@Nullable
|
||||
public static Duration secondsToDuration(@Nullable Long seconds) {
|
||||
return seconds != null ? Duration.ofSeconds(seconds) : null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 1.8
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.RedisKeyCommands;
|
||||
import org.springframework.data.redis.connection.RedisNode;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.ValueEncoding;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterCommandCallback;
|
||||
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisMultiKeyClusterCommandCallback;
|
||||
@@ -559,6 +561,36 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
|
||||
.resultsAsList().stream().mapToLong(val -> ObjectUtils.nullSafeEquals(val, Boolean.TRUE) ? 1 : 0).sum();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#encoding(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ValueEncoding encodingOf(byte[] key) {
|
||||
throw new UnsupportedOperationException("Jedis does not support OBJECT ENCODING in cluster!");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#idletime(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Duration idletime(byte[] key) {
|
||||
throw new UnsupportedOperationException("Jedis does not support OBJECT IDLETIME in cluster!");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#refcount(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long refcount(byte[] key) {
|
||||
throw new UnsupportedOperationException("Jedis does not support OBJECT REFCOUNT in cluster!");
|
||||
}
|
||||
|
||||
private DataAccessException convertJedisAccessException(Exception ex) {
|
||||
return connection.convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.SortParameters.Range;
|
||||
import org.springframework.data.redis.connection.ValueEncoding;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.convert.ListConverter;
|
||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||
@@ -188,8 +189,7 @@ abstract public class JedisConverters extends Converters {
|
||||
};
|
||||
|
||||
GEO_COORDINATE_TO_POINT_CONVERTER = geoCoordinate -> geoCoordinate != null
|
||||
? new Point(geoCoordinate.getLongitude(), geoCoordinate.getLatitude())
|
||||
: null;
|
||||
? new Point(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()) : null;
|
||||
LIST_GEO_COORDINATE_TO_POINT_CONVERTER = new ListConverter<>(GEO_COORDINATE_TO_POINT_CONVERTER);
|
||||
}
|
||||
|
||||
@@ -292,10 +292,22 @@ abstract public class JedisConverters extends Converters {
|
||||
return STRING_TO_BYTES.convert(source);
|
||||
}
|
||||
|
||||
public static String toString(byte[] source) {
|
||||
@Nullable
|
||||
public static String toString(@Nullable byte[] source) {
|
||||
return source == null ? null : SafeEncoder.encode(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given {@code source} value to the corresponding {@link ValueEncoding}.
|
||||
*
|
||||
* @param source can be {@literal null}.
|
||||
* @return the {@link ValueEncoding} for given {@code source}. Never {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public static ValueEncoding toEncoding(@Nullable byte[] source) {
|
||||
return ValueEncoding.of(toString(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param source
|
||||
* @return
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.SortingParams;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -27,6 +28,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisKeyCommands;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.ValueEncoding;
|
||||
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanCursor;
|
||||
@@ -701,6 +704,87 @@ class JedisKeyCommands implements RedisKeyCommands {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#encoding(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ValueEncoding encodingOf(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newJedisResult(connection.getRequiredPipeline().objectEncoding(key),
|
||||
JedisConverters::toEncoding, () -> RedisValueEncoding.VACANT));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newJedisResult(connection.getRequiredTransaction().objectEncoding(key),
|
||||
JedisConverters::toEncoding, () -> RedisValueEncoding.VACANT));
|
||||
return null;
|
||||
}
|
||||
return JedisConverters.toEncoding(connection.getJedis().objectEncoding(key));
|
||||
} catch (Exception ex) {
|
||||
throw connection.convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#idletime(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Duration idletime(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newJedisResult(connection.getRequiredPipeline().objectIdletime(key),
|
||||
Converters::secondsToDuration));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newJedisResult(connection.getRequiredTransaction().objectIdletime(key),
|
||||
Converters::secondsToDuration));
|
||||
return null;
|
||||
}
|
||||
|
||||
return Converters.secondsToDuration(connection.getJedis().objectIdletime(key));
|
||||
} catch (Exception ex) {
|
||||
throw connection.convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#refcount(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long refcount(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newJedisResult(connection.getRequiredPipeline().objectRefcount(key)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newJedisResult(connection.getRequiredTransaction().objectRefcount(key)));
|
||||
return null;
|
||||
}
|
||||
|
||||
return connection.getJedis().objectRefcount(key);
|
||||
} catch (Exception ex) {
|
||||
throw connection.convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPipelined() {
|
||||
return connection.isPipelined();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -32,6 +33,8 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisKeyCommands;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.ValueEncoding;
|
||||
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
@@ -691,6 +694,87 @@ class LettuceKeyCommands implements RedisKeyCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#encoding(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ValueEncoding encodingOf(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().objectEncoding(key), ValueEncoding::of,
|
||||
() -> RedisValueEncoding.VACANT));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().objectEncoding(key), ValueEncoding::of,
|
||||
() -> RedisValueEncoding.VACANT));
|
||||
return null;
|
||||
}
|
||||
|
||||
return ValueEncoding.of(getConnection().objectEncoding(key));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#idletime(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Duration idletime(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().objectIdletime(key), Converters::secondsToDuration));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(
|
||||
connection.newLettuceResult(getAsyncConnection().objectIdletime(key), Converters::secondsToDuration));
|
||||
return null;
|
||||
}
|
||||
|
||||
return Converters.secondsToDuration(getConnection().objectIdletime(key));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#refcount(byte[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long refcount(byte[] key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().objectRefcount(key)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().objectRefcount(key)));
|
||||
return null;
|
||||
}
|
||||
|
||||
return getConnection().objectRefcount(key);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPipelined() {
|
||||
return connection.isPipelined();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,6 +32,8 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.Command
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
|
||||
import org.springframework.data.redis.connection.ValueEncoding;
|
||||
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -97,8 +100,7 @@ class LettuceReactiveKeyCommands implements ReactiveKeyCommands {
|
||||
|
||||
Assert.notEmpty(keys, "Keys must not be null!");
|
||||
|
||||
return cmd.touch(keys.toArray(new ByteBuffer[keys.size()]))
|
||||
.map((value) -> new NumericResponse<>(keys, value));
|
||||
return cmd.touch(keys.toArray(new ByteBuffer[keys.size()])).map((value) -> new NumericResponse<>(keys, value));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -185,8 +187,7 @@ class LettuceReactiveKeyCommands implements ReactiveKeyCommands {
|
||||
|
||||
Assert.notEmpty(keys, "Keys must not be null!");
|
||||
|
||||
return cmd.del(keys.toArray(new ByteBuffer[keys.size()]))
|
||||
.map((value) -> new NumericResponse<>(keys, value));
|
||||
return cmd.del(keys.toArray(new ByteBuffer[keys.size()])).map((value) -> new NumericResponse<>(keys, value));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -326,7 +327,8 @@ class LettuceReactiveKeyCommands implements ReactiveKeyCommands {
|
||||
}));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveKeyCommands#move(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
@@ -340,4 +342,34 @@ class LettuceReactiveKeyCommands implements ReactiveKeyCommands {
|
||||
return cmd.move(command.getKey(), command.getDatabase()).map(value -> new BooleanResponse<>(command, value));
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveKeyCommands#encodingOf(java.nio.ByteBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Mono<ValueEncoding> encodingOf(ByteBuffer key) {
|
||||
|
||||
return connection
|
||||
.execute(cmd -> cmd.objectEncoding(key).map(ValueEncoding::of).defaultIfEmpty(RedisValueEncoding.VACANT))
|
||||
.next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveKeyCommands#idletime(java.nio.ByteBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Duration> idletime(ByteBuffer key) {
|
||||
return connection.execute(cmd -> cmd.objectIdletime(key).map(Duration::ofSeconds)).next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveKeyCommands#refcount(java.nio.ByteBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> refcount(ByteBuffer key) {
|
||||
return connection.execute(cmd -> cmd.objectRefcount(key)).next();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user