Skip to content

Commit

Permalink
Move new commands to RedisHashCommands, added HEXPIREAT, HEXPIRETIME …
Browse files Browse the repository at this point in the history
…and HPERSIST
  • Loading branch information
tishun committed Apr 23, 2024
1 parent 0e867eb commit 31c1787
Show file tree
Hide file tree
Showing 23 changed files with 1,686 additions and 539 deletions.
87 changes: 73 additions & 14 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 @@ -795,22 +811,22 @@ public RedisFuture<Boolean> expire(K key, Duration seconds, ExpireArgs expireArg
}

@Override
public RedisFuture<Boolean> hexpire(K key, long seconds, List<V> fields) {
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, List<V> fields) {
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, List<V> fields) {
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, List<V> fields) {
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);
}
Expand Down Expand Up @@ -847,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 @@ -1510,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
88 changes: 73 additions & 15 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 @@ -855,22 +871,22 @@ public Mono<Boolean> expire(K key, Duration seconds, ExpireArgs expireArgs) {
}

@Override
public Mono<Boolean> hexpire(K key, long seconds, List<V> fields) {
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, List<V> fields) {
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, List<V> fields) {
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, List<V> fields) {
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);
}
Expand Down Expand Up @@ -907,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 @@ -1577,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

0 comments on commit 31c1787

Please sign in to comment.