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 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
86 changes: 77 additions & 9 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
*/
package io.lettuce.core;

import static io.lettuce.core.protocol.CommandType.*;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.lettuce.core.GeoArgs.Unit;
import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.api.async.*;
Expand All @@ -50,6 +41,19 @@
import io.lettuce.core.protocol.ProtocolKeyword;
import io.lettuce.core.protocol.RedisCommand;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static io.lettuce.core.protocol.CommandType.EXEC;
import static io.lettuce.core.protocol.CommandType.GEORADIUS;
import static io.lettuce.core.protocol.CommandType.GEORADIUSBYMEMBER;
import static io.lettuce.core.protocol.CommandType.GEORADIUSBYMEMBER_RO;
import static io.lettuce.core.protocol.CommandType.GEORADIUS_RO;

/**
* An asynchronous and thread-safe API for a Redis connection.
*
Expand Down Expand Up @@ -794,6 +798,27 @@
return expire(key, seconds.toMillis() / 1000, expireArgs);
}

@Override
public RedisFuture<Boolean> hexpire(K key, long seconds, K... fields) {
return hexpire(key, seconds, null, fields);

Check warning on line 803 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L803

Added line #L803 was not covered by tests
}

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

Check warning on line 808 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L808

Added line #L808 was not covered by tests
}

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

Check warning on line 813 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L813

Added line #L813 was not covered by tests
}

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

Check warning on line 819 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L818-L819

Added lines #L818 - L819 were not covered by tests
}

@Override
public RedisFuture<Boolean> expireat(K key, long timestamp) {
return expireat(key, timestamp, null);
Expand Down Expand Up @@ -826,11 +851,49 @@
return expireat(key, timestamp.toEpochMilli() / 1000, expireArgs);
}

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

Check warning on line 856 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L856

Added line #L856 was not covered by tests
}

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

Check warning on line 861 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L861

Added line #L861 was not covered by tests

}

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

Check warning on line 867 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L867

Added line #L867 was not covered by tests
}

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

Check warning on line 873 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L872-L873

Added lines #L872 - L873 were not covered by tests
}

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

Check warning on line 878 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L878

Added line #L878 was not covered by tests
}

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

Check warning on line 884 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L883-L884

Added lines #L883 - L884 were not covered by tests
}

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

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

Check warning on line 894 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L894

Added line #L894 was not covered by tests
}

@Override
public <T> RedisFuture<T> fcall(String function, ScriptOutputType type, K... keys) {
return dispatch(commandBuilder.fcall(function, type, false, keys));
Expand Down Expand Up @@ -1489,6 +1552,11 @@
return dispatch(commandBuilder.persist(key));
}

@Override
public RedisFuture<Boolean> hpersist(K key, K... fields) {
return dispatch(commandBuilder.hpersist(key, fields));

Check warning on line 1557 in src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L1557

Added line #L1557 was not covered by tests
}

@Override
public RedisFuture<Boolean> pexpire(K key, long milliseconds) {
return pexpire(key, milliseconds, null);
Expand Down
87 changes: 77 additions & 10 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
*/
package io.lettuce.core;

import static io.lettuce.core.protocol.CommandType.*;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import io.lettuce.core.GeoArgs.Unit;
import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.api.reactive.*;
Expand Down Expand Up @@ -59,6 +49,20 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import static io.lettuce.core.protocol.CommandType.EXEC;
import static io.lettuce.core.protocol.CommandType.GEORADIUS;
import static io.lettuce.core.protocol.CommandType.GEORADIUSBYMEMBER;
import static io.lettuce.core.protocol.CommandType.GEORADIUSBYMEMBER_RO;
import static io.lettuce.core.protocol.CommandType.GEORADIUS_RO;

/**
* A reactive and thread-safe API for a Redis connection.
*
Expand Down Expand Up @@ -854,6 +858,27 @@
return expire(key, seconds.toMillis() / 1000, expireArgs);
}

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

Check warning on line 863 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L863

Added line #L863 was not covered by tests
}

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

Check warning on line 868 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L868

Added line #L868 was not covered by tests
}

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

Check warning on line 873 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L873

Added line #L873 was not covered by tests
}

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

Check warning on line 879 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L878-L879

Added lines #L878 - L879 were not covered by tests
}

@Override
public Mono<Boolean> expireat(K key, long timestamp) {
return expireat(key, timestamp, null);
Expand Down Expand Up @@ -886,11 +911,48 @@
return expireat(key, timestamp.toEpochMilli() / 1000, expireArgs);
}

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

Check warning on line 916 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L916

Added line #L916 was not covered by tests
}

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

Check warning on line 921 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L921

Added line #L921 was not covered by tests
}

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

Check warning on line 926 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L926

Added line #L926 was not covered by tests
}

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

Check warning on line 932 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L931-L932

Added lines #L931 - L932 were not covered by tests
}

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

Check warning on line 937 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L937

Added line #L937 was not covered by tests
}

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

Check warning on line 943 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L942-L943

Added lines #L942 - L943 were not covered by tests
}

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

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

Check warning on line 953 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L953

Added line #L953 was not covered by tests
}

@Override
public <T> Flux<T> fcall(String function, ScriptOutputType type, K... keys) {
return createFlux(() -> commandBuilder.fcall(function, type, false, keys));
Expand Down Expand Up @@ -1556,6 +1618,11 @@
return createMono(() -> commandBuilder.persist(key));
}

@Override
public Mono<Boolean> hpersist(K key, K... fields) {
return createMono(() -> commandBuilder.hpersist(key, fields));

Check warning on line 1623 in src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L1623

Added line #L1623 was not covered by tests
}

@Override
public Mono<Boolean> pexpire(K key, long milliseconds) {
return pexpire(key, milliseconds, null);
Expand Down
77 changes: 64 additions & 13 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@
*/
package io.lettuce.core;

import static io.lettuce.core.internal.LettuceStrings.*;
import static io.lettuce.core.protocol.CommandKeyword.*;
import static io.lettuce.core.protocol.CommandType.*;
import static io.lettuce.core.protocol.CommandType.COPY;
import static io.lettuce.core.protocol.CommandType.SAVE;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.lettuce.core.Range.Boundary;
import io.lettuce.core.XReadArgs.StreamOffset;
import io.lettuce.core.codec.RedisCodec;
Expand All @@ -48,6 +35,19 @@
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.RedisCommand;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static io.lettuce.core.internal.LettuceStrings.string;
import static io.lettuce.core.protocol.CommandKeyword.*;
import static io.lettuce.core.protocol.CommandType.*;
import static io.lettuce.core.protocol.CommandType.COPY;
import static io.lettuce.core.protocol.CommandType.SAVE;

/**
* @param <K>
* @param <V>
Expand Down Expand Up @@ -978,6 +978,38 @@ 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, K... fields) {
notNullKey(key);
notEmpty(fields);

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

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

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

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

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

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

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

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

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

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

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

Command<K, V, 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);
}

Command<K, V, String> flushall() {
return createCommand(FLUSHALL, new StatusOutput<>(codec));
}
Expand Down Expand Up @@ -2043,6 +2084,16 @@ Command<K, V, Boolean> persist(K key) {
return createCommand(PERSIST, new BooleanOutput<>(codec), key);
}

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);

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

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

Expand Down
Loading
Loading