Skip to content

Commit 70a3e5d

Browse files
christophstroblmp911de
authored andcommitted
DATAREDIS-716 - Add support for OBJECT REFCOUNT, ENCODING and IDLETIME.
Original pull request: #337.
1 parent f8d63f4 commit 70a3e5d

14 files changed

+688
-19
lines changed

src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18-
import java.util.*;
18+
import java.time.Duration;
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.HashMap;
22+
import java.util.LinkedHashMap;
23+
import java.util.LinkedList;
24+
import java.util.List;
25+
import java.util.Map;
1926
import java.util.Map.Entry;
27+
import java.util.Properties;
28+
import java.util.Queue;
29+
import java.util.Set;
2030
import java.util.concurrent.TimeUnit;
2131

2232
import org.apache.commons.logging.Log;
@@ -1079,6 +1089,33 @@ public List<byte[]> sort(byte[] key, SortParameters params) {
10791089
return convertAndReturn(delegate.sort(key, params), identityConverter);
10801090
}
10811091

1092+
/*
1093+
* (non-Javadoc)
1094+
* @see org.springframework.data.redis.connection.StringRedisConnection#encoding(byte[])
1095+
*/
1096+
@Override
1097+
public ValueEncoding encodingOf(byte[] key) {
1098+
return convertAndReturn(delegate.encodingOf(key), identityConverter);
1099+
}
1100+
1101+
/*
1102+
* (non-Javadoc)
1103+
* @see org.springframework.data.redis.connection.StringRedisConnection#idletime(byte[])
1104+
*/
1105+
@Override
1106+
public Duration idletime(byte[] key) {
1107+
return convertAndReturn(delegate.idletime(key), identityConverter);
1108+
}
1109+
1110+
/*
1111+
* (non-Javadoc)
1112+
* @see org.springframework.data.redis.connection.StringRedisConnection#refcount(byte[])
1113+
*/
1114+
@Override
1115+
public Long refcount(byte[] key) {
1116+
return convertAndReturn(delegate.refcount(key), identityConverter);
1117+
}
1118+
10821119
/*
10831120
* (non-Javadoc)
10841121
* @see org.springframework.data.redis.connection.RedisSetCommands#sPop(byte[])
@@ -1305,7 +1342,7 @@ public Double zIncrBy(byte[] key, double increment, byte[] value) {
13051342
return convertAndReturn(delegate.zIncrBy(key, increment, value), identityConverter);
13061343
}
13071344

1308-
/*
1345+
/*
13091346
* (non-Javadoc)
13101347
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
13111348
*/
@@ -1566,7 +1603,7 @@ public Double zScore(byte[] key, byte[] value) {
15661603
return convertAndReturn(delegate.zScore(key, value), identityConverter);
15671604
}
15681605

1569-
/*
1606+
/*
15701607
* (non-Javadoc)
15711608
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
15721609
*/
@@ -2399,6 +2436,33 @@ public List<String> sort(String key, SortParameters params) {
23992436
return convertAndReturn(delegate.sort(serialize(key), params), byteListToStringList);
24002437
}
24012438

2439+
/*
2440+
* (non-Javadoc)
2441+
* @see org.springframework.data.redis.connection.StringRedisConnection#encoding(java.lang.String)
2442+
*/
2443+
@Override
2444+
public ValueEncoding encodingOf(String key) {
2445+
return encodingOf(serialize(key));
2446+
}
2447+
2448+
/*
2449+
* (non-Javadoc)
2450+
* @see org.springframework.data.redis.connection.StringRedisConnection#idletime(java.lang.String)
2451+
*/
2452+
@Override
2453+
public Duration idletime(String key) {
2454+
return idletime(serialize(key));
2455+
}
2456+
2457+
/*
2458+
* (non-Javadoc)
2459+
* @see org.springframework.data.redis.connection.StringRedisConnection#refcount(java.lang.String)
2460+
*/
2461+
@Override
2462+
public Long refcount(String key) {
2463+
return refcount(serialize(key));
2464+
}
2465+
24022466
/*
24032467
* (non-Javadoc)
24042468
* @see org.springframework.data.redis.connection.StringRedisConnection#sPop(java.lang.String)

src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18+
import java.time.Duration;
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Map.Entry;
@@ -223,6 +224,27 @@ default Long sort(byte[] key, SortParameters params, byte[] sortKey) {
223224
return keyCommands().sort(key, params, sortKey);
224225
}
225226

227+
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
228+
@Override
229+
@Deprecated
230+
default ValueEncoding encodingOf(byte[] key) {
231+
return keyCommands().encodingOf(key);
232+
}
233+
234+
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
235+
@Override
236+
@Deprecated
237+
default Duration idletime(byte[] key) {
238+
return keyCommands().idletime(key);
239+
}
240+
241+
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
242+
@Override
243+
@Deprecated
244+
default Long refcount(byte[] key) {
245+
return keyCommands().refcount(key);
246+
}
247+
226248
// STRING COMMANDS
227249

228250
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */

src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,37 @@ default Mono<Boolean> move(ByteBuffer key, int database) {
692692
* @see <a href="http://redis.io/commands/move">Redis Documentation: MOVE</a>
693693
*/
694694
Flux<BooleanResponse<MoveCommand>> move(Publisher<MoveCommand> commands);
695+
696+
/**
697+
* Get the type of internal representation used for storing the value at the given {@code key}.
698+
*
699+
* @param key must not be {@literal null}.
700+
* @return the {@link Mono} emitting {@link org.springframework.data.redis.connection.ValueEncoding}.
701+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
702+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT ENCODING</a>
703+
* @since 2.1
704+
*/
705+
Mono<ValueEncoding> encodingOf(ByteBuffer key);
706+
707+
/**
708+
* Get the {@link Duration} since the object stored at the given {@code key} is idle.
709+
*
710+
* @param key must not be {@literal null}.
711+
* @return the {@link Mono} emitting the idletime of the key of {@link Mono#empty()} if the key does not exist.
712+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
713+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT IDLETIME</a>
714+
* @since 2.1
715+
*/
716+
Mono<Duration> idletime(ByteBuffer key);
717+
718+
/**
719+
* Get the number of references of the value associated with the specified {@code key}.
720+
*
721+
* @param key must not be {@literal null}.
722+
* @return {@link Mono#empty()} if key does not exist.
723+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
724+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT REFCOUNT</a>
725+
* @since 2.1
726+
*/
727+
Mono<Long> refcount(ByteBuffer key);
695728
}

src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18+
import java.time.Duration;
1819
import java.util.List;
1920
import java.util.Set;
2021
import java.util.concurrent.TimeUnit;
@@ -303,4 +304,42 @@ default Boolean exists(byte[] key) {
303304
* @see <a href="http://redis.io/commands/restore">Redis Documentation: RESTORE</a>
304305
*/
305306
void restore(byte[] key, long ttlInMillis, byte[] serializedValue);
307+
308+
/**
309+
* Get the type of internal representation used for storing the value at the given {@code key}.
310+
*
311+
* @param key must not be {@literal null}.
312+
* @return {@link org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding#VACANT} if key does not
313+
* exist or {@literal null} when used in pipeline / transaction.
314+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
315+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT ENCODING</a>
316+
* @since 2.1
317+
*/
318+
@Nullable
319+
ValueEncoding encodingOf(byte[] key);
320+
321+
/**
322+
* Get the {@link Duration} since the object stored at the given {@code key} is idle.
323+
*
324+
* @param key must not be {@literal null}.
325+
* @return {@literal null} if key does not exist or when used in pipeline / transaction.
326+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
327+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT IDLETIME</a>
328+
* @since 2.1
329+
*/
330+
@Nullable
331+
Duration idletime(byte[] key);
332+
333+
/**
334+
* Get the number of references of the value associated with the specified {@code key}.
335+
*
336+
* @param key must not be {@literal null}.
337+
* @return {@literal null} if key does not exist or when used in pipeline / transaction.
338+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
339+
* @see <a href="http://redis.io/commands/object">Redis Documentation: OBJECT REFCOUNT</a>
340+
* @since 2.1
341+
*/
342+
@Nullable
343+
Long refcount(byte[] key);
344+
306345
}

src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18+
import java.time.Duration;
1819
import java.util.Collection;
1920
import java.util.List;
2021
import java.util.Map;
@@ -317,6 +318,39 @@ interface StringTuple extends Tuple {
317318
*/
318319
Long sort(String key, SortParameters params, String storeKey);
319320

321+
/**
322+
* Get the type of internal representation used for storing the value at the given {@code key}.
323+
*
324+
* @param key must not be {@literal null}.
325+
* @return {@literal null} if key does not exist or when used in pipeline / transaction.
326+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
327+
* @since 2.1
328+
*/
329+
@Nullable
330+
ValueEncoding encodingOf(String key);
331+
332+
/**
333+
* Get the {@link Duration} since the object stored at the given {@code key} is idle.
334+
*
335+
* @param key must not be {@literal null}.
336+
* @return {@literal null} if key does not exist or when used in pipeline / transaction.
337+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
338+
* @since 2.1
339+
*/
340+
@Nullable
341+
Duration idletime(String key);
342+
343+
/**
344+
* Get the number of references of the value associated with the specified {@code key}.
345+
*
346+
* @param key must not be {@literal null}.
347+
* @return {@literal null} if key does not exist or when used in pipeline / transaction.
348+
* @throws IllegalArgumentException if {@code key} is {@literal null}.
349+
* @since 2.1
350+
*/
351+
@Nullable
352+
Long refcount(String key);
353+
320354
// -------------------------------------------------------------------------
321355
// Methods dealing with values/Redis strings
322356
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)