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 3 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
100 changes: 90 additions & 10 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
*/
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.*;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisAclAsyncCommands;
import io.lettuce.core.api.async.RedisGeoAsyncCommands;
import io.lettuce.core.api.async.RedisHLLAsyncCommands;
import io.lettuce.core.api.async.RedisHashAsyncCommands;
import io.lettuce.core.api.async.RedisKeyAsyncCommands;
import io.lettuce.core.api.async.RedisListAsyncCommands;
import io.lettuce.core.api.async.RedisScriptingAsyncCommands;
import io.lettuce.core.api.async.RedisServerAsyncCommands;
import io.lettuce.core.api.async.RedisSetAsyncCommands;
import io.lettuce.core.api.async.RedisSortedSetAsyncCommands;
import io.lettuce.core.api.async.RedisStringAsyncCommands;
import io.lettuce.core.api.async.RedisTransactionalAsyncCommands;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.codec.Base16;
import io.lettuce.core.codec.RedisCodec;
Expand All @@ -50,6 +53,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 +810,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, K... fields) {
return hexpire(key, seconds, null, fields);
}

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

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

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

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

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

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

}

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

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

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

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

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

@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 +1564,11 @@ public RedisFuture<Boolean> persist(K key) {
return dispatch(commandBuilder.persist(key));
}

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

@Override
public RedisFuture<Boolean> pexpire(K key, long milliseconds) {
return pexpire(key, milliseconds, null);
Expand Down
101 changes: 90 additions & 11 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
*/
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.*;
import io.lettuce.core.api.reactive.BaseRedisReactiveCommands;
import io.lettuce.core.api.reactive.RedisAclReactiveCommands;
import io.lettuce.core.api.reactive.RedisGeoReactiveCommands;
import io.lettuce.core.api.reactive.RedisHLLReactiveCommands;
import io.lettuce.core.api.reactive.RedisHashReactiveCommands;
import io.lettuce.core.api.reactive.RedisKeyReactiveCommands;
import io.lettuce.core.api.reactive.RedisListReactiveCommands;
import io.lettuce.core.api.reactive.RedisScriptingReactiveCommands;
import io.lettuce.core.api.reactive.RedisServerReactiveCommands;
import io.lettuce.core.api.reactive.RedisSetReactiveCommands;
import io.lettuce.core.api.reactive.RedisSortedSetReactiveCommands;
import io.lettuce.core.api.reactive.RedisStringReactiveCommands;
import io.lettuce.core.api.reactive.RedisTransactionalReactiveCommands;
import io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands;
import io.lettuce.core.codec.Base16;
import io.lettuce.core.codec.RedisCodec;
Expand Down Expand Up @@ -59,6 +61,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 +870,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, K... fields) {
return hexpire(key, seconds, null, fields);
}

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

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

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

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

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

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

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

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

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

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

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

@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 +1630,11 @@ public Mono<Boolean> persist(K key) {
return createMono(() -> commandBuilder.persist(key));
}

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

@Override
public Mono<Boolean> pexpire(K key, long milliseconds) {
return pexpire(key, milliseconds, null);
Expand Down
Loading
Loading