Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OBJECT FREQ #1686

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,11 @@ public RedisFuture<String> objectEncoding(K key) {
return dispatch(commandBuilder.objectEncoding(key));
}

@Override
public RedisFuture<Long> objectFreq(K key) {
return dispatch(commandBuilder.objectFreq(key));
}

@Override
public RedisFuture<Long> objectIdletime(K key) {
return dispatch(commandBuilder.objectIdletime(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,11 @@ public Mono<String> objectEncoding(K key) {
return createMono(() -> commandBuilder.objectEncoding(key));
}

@Override
public Mono<Long> objectFreq(K key) {
return createMono(() -> commandBuilder.objectFreq(key));
}

@Override
public Mono<Long> objectIdletime(K key) {
return createMono(() -> commandBuilder.objectIdletime(key));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,13 @@ Command<K, V, String> objectEncoding(K key) {
return createCommand(OBJECT, new StatusOutput<>(codec), args);
}

Command<K, V, Long> objectFreq(K key) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(FREQ).addKey(key);
return createCommand(OBJECT, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> objectIdletime(K key) {
notNullKey(key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ public interface RedisKeyAsyncCommands<K, V> {
*/
RedisFuture<String> objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
RedisFuture<Long> objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ public interface RedisKeyReactiveCommands<K, V> {
*/
Mono<String> objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
Mono<Long> objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public interface RedisKeyCommands<K, V> {
*/
String objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
Long objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public interface NodeSelectionKeyAsyncCommands<K, V> {
*/
AsyncExecutions<String> objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
AsyncExecutions<Long> objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public interface NodeSelectionKeyCommands<K, V> {
*/
Executions<String> objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
Executions<Long> objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum CommandKeyword implements ProtocolKeyword {

BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELUSER, DESC, SOFT, HARD, ENCODING,

FAILOVER, FORGET, FLUSH, FORCE, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE,
FAILOVER, FORGET, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE,

IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LIST, LOAD, LOG, MATCH,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ interface RedisKeyCoroutinesCommands<K : Any, V : Any> {
*/
suspend fun objectEncoding(key: K): String?

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
suspend fun objectFreq(key: K): Long?

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ internal class RedisKeyCoroutinesCommandsImpl<K : Any, V : Any>(internal val ops

override suspend fun objectEncoding(key: K): String? = ops.objectEncoding(key).awaitFirstOrNull()

override suspend fun objectFreq(key: K): Long? = ops.objectFreq(key).awaitFirstOrNull()

override suspend fun objectIdletime(key: K): Long? = ops.objectIdletime(key).awaitFirstOrNull()

override suspend fun objectRefcount(key: K): Long? = ops.objectRefcount(key).awaitFirstOrNull()
Expand Down
9 changes: 9 additions & 0 deletions src/main/templates/io/lettuce/core/api/RedisKeyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ public interface RedisKeyCommands<K, V> {
*/
String objectEncoding(K key);

/**
* returns the logarithmic access frequency counter of the object stored at the specified key.
*
* @param key the key.
* @return Long.
* @since 6.1
*/
Long objectFreq(K key);

/**
* returns the number of seconds since the object stored at the specified key is idle (not requested by read or write
* operations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ void objectEncoding() {
assertThat(redis.objectEncoding(key)).isEqualTo("int");
}

@Test
void objectFreq() {
redis.configSet("maxmemory-policy", "allkeys-lfu");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaks OBJECT IDLETIME

redis.set(key, value);
assertThat(redis.objectFreq(key)).isGreaterThan(0);
}

@Test
void objectIdletime() {
redis.set(key, value);
Expand Down