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 HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL and HPTTL #2857

Merged
merged 12 commits into from
May 22, 2024
70 changes: 69 additions & 1 deletion src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,74 @@ public RedisFuture<Boolean> hexpire(K key, Duration seconds, ExpireArgs expireAr
return hexpire(key, seconds.toMillis() / 1000, expireArgs, fields);
}

@Override
public RedisFuture<List<Long>> httl(K key, K... fields) {
return dispatch(commandBuilder.httl(key, fields));
}

@Override
public RedisFuture<Boolean> hpexpire(K key, long milliseconds, K... fields) {
return hpexpire(key, milliseconds, null, fields);
}

@Override
public RedisFuture<Boolean> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields) {
return dispatch(commandBuilder.hpexpire(key, milliseconds, expireArgs, fields));
}

@Override
public RedisFuture<Boolean> hpexpire(K key, Duration milliseconds, K... fields) {
return hpexpire(key, milliseconds, null, fields);
}

@Override
public RedisFuture<Boolean> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(milliseconds, "Timeout must not be null");
return hpexpire(key, milliseconds.toMillis(), expireArgs, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, Date timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(timestamp, "Timestamp must not be null");
return hpexpireat(key, timestamp.getTime(), expireArgs, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, Instant timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(timestamp, "Timestamp must not be null");
return hpexpireat(key, timestamp.toEpochMilli(), expireArgs, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, long timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

@Override
public RedisFuture<Boolean> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) {
return dispatch(commandBuilder.hpexpireat(key, timestamp, expireArgs, fields));
}

@Override
public RedisFuture<List<Long>> hpexpiretime(K key, K... fields) {
return dispatch(commandBuilder.hpexpiretime(key, fields));
}

@Override
public RedisFuture<List<Long>> hpttl(K key, K... fields) {
return dispatch(commandBuilder.hpttl(key, fields));
}

@Override
public RedisFuture<Boolean> expireat(K key, long timestamp) {
return expireat(key, timestamp, null);
Expand Down Expand Up @@ -890,7 +958,7 @@ public RedisFuture<Long> expiretime(K key) {
}

@Override
public RedisFuture<Long> hexpiretime(K key, K... fields) {
public RedisFuture<List<Long>> hexpiretime(K key, K... fields) {
return dispatch(commandBuilder.hexpiretime(key, fields));
}

Expand Down
72 changes: 70 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,76 @@ public Mono<Long> expiretime(K key) {
}

@Override
public Mono<Long> hexpiretime(K key, K... fields) {
return createMono(() -> commandBuilder.hexpiretime(key, fields));
public Flux<Long> hexpiretime(K key, K... fields) {
return createDissolvingFlux(() -> commandBuilder.hexpiretime(key, fields));
}

@Override
public Flux<Long> httl(K key, K... fields) {
return createDissolvingFlux(() -> commandBuilder.httl(key, fields));
}

@Override
public Mono<Boolean> hpexpire(K key, long milliseconds, K... fields) {
return hpexpire(key, milliseconds, null, fields);
}

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

@Override
public Mono<Boolean> hpexpire(K key, Duration milliseconds, K... fields) {
return hpexpire(key, milliseconds, null, fields);
}

@Override
public Mono<Boolean> hpexpire(K key, Duration milliseconds, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(milliseconds, "Timeout must not be null");
return hpexpire(key, milliseconds.toMillis(), expireArgs, fields);
}

@Override
public Mono<Boolean> hpexpireat(K key, Date timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

@Override
public Mono<Boolean> hpexpireat(K key, Date timestamp, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(timestamp, "Timestamp must not be null");
return hpexpireat(key, timestamp.getTime(), expireArgs, fields);
}

@Override
public Mono<Boolean> hpexpireat(K key, Instant timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

@Override
public Mono<Boolean> hpexpireat(K key, Instant timestamp, ExpireArgs expireArgs, K... fields) {
LettuceAssert.notNull(timestamp, "Timestamp must not be null");
return hpexpireat(key, timestamp.toEpochMilli(), expireArgs, fields);
}

@Override
public Mono<Boolean> hpexpireat(K key, long timestamp, K... fields) {
return hpexpireat(key, timestamp, null, fields);
}

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

@Override
public Flux<Long> hpexpiretime(K key, K... fields) {
return createDissolvingFlux(() -> commandBuilder.hpexpiretime(key, fields));
}

@Override
public Flux<Long> hpttl(K key, K... fields) {
return createDissolvingFlux(() -> commandBuilder.hpttl(key, fields));
}

@Override
Expand Down
77 changes: 67 additions & 10 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,7 @@ Command<K, V, Boolean> hexpire(K key, long seconds, ExpireArgs expireArgs, K...
expireArgs.build(args);
}

args.add(fields.length);
args.addKeys(fields);
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HEXPIRE, new BooleanOutput<>(codec), args);
}
Expand All @@ -1004,12 +1003,71 @@ Command<K, V, Boolean> hexpireat(K key, long seconds, ExpireArgs expireArgs, K..
expireArgs.build(args);
}

args.add(fields.length);
args.addKeys(fields);
args.add(FIELDS).add(fields.length).addKeys(fields);

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

Command<K, V, List<Long>> httl(K key, K... fields) {
notNullKey(key);
notEmpty(fields);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HTTL, new IntegerListOutput<>(codec), args);
}

Command<K, V, Boolean> hpexpire(K key, long milliseconds, ExpireArgs expireArgs, K... fields) {
notNullKey(key);
notEmpty(fields);

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

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

args.add(FIELDS).add(fields.length).addKeys(fields);

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

Command<K, V, Boolean> hpexpireat(K key, long timestamp, ExpireArgs expireArgs, K... fields) {
notNullKey(key);
notEmpty(fields);

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

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

args.add(FIELDS).add(fields.length).addKeys(fields);

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

Command<K, V, List<Long>> hpexpiretime(K key, K... fields) {
notNullKey(key);
notEmpty(fields);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
tishun marked this conversation as resolved.
Show resolved Hide resolved
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HPEXPIRETIME, new IntegerListOutput<>(codec), args);
}

Command<K, V, List<Long>> hpttl(K key, K... fields) {
notNullKey(key);
notEmpty(fields);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HPTTL, new IntegerListOutput<>(codec), args);
}

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

Expand All @@ -1029,13 +1087,13 @@ Command<K, V, Long> expiretime(K key) {
return createCommand(EXPIRETIME, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> hexpiretime(K key, K... fields) {
Command<K, V, List<Long>> hexpiretime(K key, K... fields) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
args.add(fields.length);
args.addKeys(fields);
return createCommand(HEXPIRETIME, new IntegerOutput<>(codec), args);
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HEXPIRETIME, new IntegerListOutput<>(codec), args);
}

Command<K, V, String> flushall() {
Expand Down Expand Up @@ -2088,8 +2146,7 @@ Command<K, V, Boolean> hpersist(K key, K... fields) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
args.add(fields.length);
args.addKeys(fields);
args.add(FIELDS).add(fields.length).addKeys(fields);

return createCommand(HPERSIST, new BooleanOutput<>(codec), args);
}
Expand Down
Loading
Loading