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

Implement HEXPIRE, HEXPIREAT, HEXPIRETIME and HPERSIST #2836

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,27 @@ public RedisFuture<Boolean> expire(K key, Duration seconds, ExpireArgs expireArg
return expire(key, seconds.toMillis() / 1000, expireArgs);
}

@Override
public RedisFuture<Boolean> hexpire(K key, long seconds, List<V> fields) {
tishun marked this conversation as resolved.
Show resolved Hide resolved
return hexpire(key, seconds, null, fields);
}

@Override
public RedisFuture<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields) {
return dispatch(commandBuilder.hexpire(key, seconds, expireArgs, fields));
}

@Override
public RedisFuture<Boolean> hexpire(K key, Duration seconds, List<V> fields) {
return hexpire(key, seconds, null, fields);
}

@Override
public RedisFuture<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields) {
LettuceAssert.notNull(seconds, "Timeout must not be null");
return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields);
}

@Override
public RedisFuture<Boolean> expireat(K key, long timestamp) {
return expireat(key, timestamp, null);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,27 @@ public Mono<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs) {
return expire(key, seconds.toMillis() / 1000, expireArgs);
}

@Override
public Mono<Boolean> hexpire(K key, long seconds, List<V> fields) {
return hexpire(key, seconds, null, fields);
}

@Override
public Mono<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields) {
return createMono(() -> commandBuilder.hexpire(key, seconds, expireArgs, fields));
}

@Override
public Mono<Boolean> hexpire(K key, Duration seconds, List<V> fields) {
return hexpire(key, seconds, null, fields);
}

@Override
public Mono<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields) {
LettuceAssert.notNull(seconds, "Timeout must not be null");
return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields);
}

@Override
public Mono<Boolean> expireat(K key, long timestamp) {
return expireat(key, timestamp, null);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,23 @@ Command<K, V, Boolean> expire(K key, long seconds, ExpireArgs expireArgs) {
return createCommand(EXPIRE, new BooleanOutput<>(codec), args);
}

Command<K, V, Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields) {
notNullKey(key);
notEmpty(fields == null ? new Object[]{} : fields.toArray());

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key).add(seconds);

if (expireArgs != null) {
expireArgs.build(args);
}

args.add(fields.size());

fields.forEach(args::addValue);

return createCommand(HEXPIRE, new BooleanOutput<>(codec), args);
}

Command<K, V, Boolean> expireat(K key, long timestamp, ExpireArgs expireArgs) {
notNullKey(key);

Expand Down
50 changes: 50 additions & 0 deletions src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,56 @@ public interface RedisKeyAsyncCommands<K, V> {
*/
RedisFuture<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
RedisFuture<Boolean> hexpire(K key, long seconds, List<V> fields);
tishun marked this conversation as resolved.
Show resolved Hide resolved

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param expireArgs the expire arguments.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
RedisFuture<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
RedisFuture<Boolean> hexpire(K key, Duration seconds, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param expireArgs the {@link ExpireArgs}.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
RedisFuture<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the expiration for a key as a UNIX timestamp.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -147,6 +148,56 @@ public interface RedisKeyReactiveCommands<K, V> {
*/
Mono<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Mono<Boolean> hexpire(K key, long seconds, List<V> fields);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param expireArgs the expire arguments.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Mono<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Mono<Boolean> hexpire(K key, Duration seconds, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param expireArgs the {@link ExpireArgs}.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Mono<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the expiration for a key as a UNIX timestamp.
*
Expand Down
50 changes: 50 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 @@ -146,6 +146,56 @@ public interface RedisKeyCommands<K, V> {
*/
Boolean expire(K key, Duration seconds, ExpireArgs expireArgs);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Boolean hexpire(K key, long seconds, List<V> fields);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param expireArgs the expire arguments.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Boolean hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Boolean hexpire(K key, Duration seconds, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param expireArgs the {@link ExpireArgs}.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Boolean hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the expiration for a key as a UNIX timestamp.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,56 @@ public interface NodeSelectionKeyAsyncCommands<K, V> {
*/
AsyncExecutions<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
AsyncExecutions<Boolean> hexpire(K key, long seconds, List<V> fields);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param expireArgs the expire arguments.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
AsyncExecutions<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
AsyncExecutions<Boolean> hexpire(K key, Duration seconds, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param expireArgs the {@link ExpireArgs}.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
AsyncExecutions<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the expiration for a key as a UNIX timestamp.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,56 @@ public interface NodeSelectionKeyCommands<K, V> {
*/
Executions<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Executions<Boolean> hexpire(K key, long seconds, List<V> fields);

/**
* Set the time to live (in seconds) for a {@link List} of fields, belonging to a certain key.
*
* @param key the key of the fields.
* @param seconds the seconds type: long.
* @param expireArgs the expire arguments.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Executions<Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Executions<Boolean> hexpire(K key, Duration seconds, List<V> fields);

/**
* Set the time to live for a {@link List} of fields, belonging to a certain key.
*
* @param key the key.
* @param seconds the TTL {@link Duration}
* @param expireArgs the {@link ExpireArgs}.
* @param fields a {@link List} of fields to set the TTL for.
* @return Boolean integer-reply specifically: {@code true} if the timeout was set. {@code false} if {@code key} does not
* exist or the timeout could not be set.
* @since 7.0
*/
Executions<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireArgs, List<V> fields);

/**
* Set the expiration for a key as a UNIX timestamp.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum CommandType implements ProtocolKeyword {

// Keys

COPY, DEL, DUMP, EXISTS, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, TYPE, SCAN, UNLINK,
COPY, DEL, DUMP, EXISTS, HEXPIRE, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, TOUCH, TTL, TYPE, SCAN, UNLINK,

// String

Expand Down
Loading
Loading