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

Support CONFIG GET/SET with multiple parameters #1988

Closed
Closed
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
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ public RedisFuture<Map<String, String>> configGet(String parameter) {
return dispatch(commandBuilder.configGet(parameter));
}

@Override
public RedisFuture<Map<String, String>> configGet(String... parameters) {
return dispatch(commandBuilder.configGet(parameters));
}

@Override
public RedisFuture<String> configResetstat() {
return dispatch(commandBuilder.configResetstat());
Expand All @@ -511,6 +516,11 @@ public RedisFuture<String> configSet(String parameter, String value) {
return dispatch(commandBuilder.configSet(parameter, value));
}

@Override
public RedisFuture<String> configSet(Map<String, String> kvs) {
return dispatch(commandBuilder.configSet(kvs));
}

@Override
public RedisFuture<Long> dbsize() {
return dispatch(commandBuilder.dbsize());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ public Mono<Map<String, String>> configGet(String parameter) {
return createMono(() -> commandBuilder.configGet(parameter));
}

@Override
public Mono<Map<String, String>> configGet(String... parameters) {
return createMono(() -> commandBuilder.configGet(parameters));
}

@Override
public Mono<String> configResetstat() {
return createMono(commandBuilder::configResetstat);
Expand All @@ -531,6 +536,11 @@ public Mono<String> configSet(String parameter, String value) {
return createMono(() -> commandBuilder.configSet(parameter, value));
}

@Override
public Mono<String> configSet(Map<String, String> kvs) {
return createMono(() -> commandBuilder.configSet(kvs));
}

@SuppressWarnings("unchecked")
public <T, R> Flux<R> createDissolvingFlux(Supplier<RedisCommand<K, V, T>> commandSupplier) {
return (Flux<R>) createFlux(commandSupplier, true);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,17 @@ Command<K, V, Map<String, String>> configGet(String parameter) {
return createCommand(CONFIG, new MapOutput<>((RedisCodec) StringCodec.UTF8), args);
}

Command<K, V, Map<String, String>> configGet(String... parameters) {
LettuceAssert.notNull(parameters, "Parameters " + MUST_NOT_BE_NULL);
LettuceAssert.notEmpty(parameters, "Parameters " + MUST_NOT_BE_EMPTY);

CommandArgs<K, V> args = new CommandArgs<>((RedisCodec) StringCodec.UTF8).add(GET);
for (String parameter : parameters) {
args.add(parameter);
}
return createCommand(CONFIG, new MapOutput<>((RedisCodec) StringCodec.UTF8), args);
}

Command<K, V, String> configResetstat() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(RESETSTAT);
return createCommand(CONFIG, new StatusOutput<>(codec), args);
Expand All @@ -683,6 +694,18 @@ Command<K, V, String> configSet(String parameter, String value) {
return createCommand(CONFIG, new StatusOutput<>(codec), args);
}

Command<K, V, String> configSet(Map<String, String> configValues) {
LettuceAssert.notNull(configValues, "ConfigValues " + MUST_NOT_BE_NULL);
LettuceAssert.isTrue(!configValues.isEmpty(), "ConfigValues " + MUST_NOT_BE_EMPTY);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(SET);
configValues.forEach((parameter, value) -> {
args.add(parameter);
args.add(value);
});
return createCommand(CONFIG, new StatusOutput<>(codec), args);
}

Command<K, V, Long> dbsize() {
return createCommand(DBSIZE, new IntegerOutput<>(codec));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public interface RedisServerAsyncCommands<K, V> {
*/
RedisFuture<Map<String, String>> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
RedisFuture<Map<String, String>> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -206,6 +215,15 @@ public interface RedisServerAsyncCommands<K, V> {
*/
RedisFuture<String> configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
RedisFuture<String> configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public interface RedisServerReactiveCommands<K, V> {
*/
Mono<Map<String, String>> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
Mono<Map<String, String>> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -206,6 +215,15 @@ public interface RedisServerReactiveCommands<K, V> {
*/
Mono<String> configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
Mono<String> configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ public interface RedisServerCommands<K, V> {
*/
Map<String, String> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
Map<String, String> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -205,6 +214,15 @@ public interface RedisServerCommands<K, V> {
*/
String configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
String configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
*/
AsyncExecutions<Map<String, String>> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
AsyncExecutions<Map<String, String>> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -205,6 +214,15 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
*/
AsyncExecutions<String> configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
AsyncExecutions<String> configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -181,6 +181,15 @@ public interface NodeSelectionServerCommands<K, V> {
*/
Executions<Map<String, String>> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
Executions<Map<String, String>> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -205,6 +214,15 @@ public interface NodeSelectionServerCommands<K, V> {
*/
Executions<String> configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
Executions<String> configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ interface RedisServerCoroutinesCommands<K : Any, V : Any> {
*/
suspend fun configGet(parameter: String): Map<String, String>?

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map<String, String> bulk-string-reply.
* @since 7.0
*/
suspend fun configGet(vararg parameters: String): Map<String, String>?

/**
* Reset the stats returned by INFO.
*
Expand All @@ -201,6 +210,15 @@ interface RedisServerCoroutinesCommands<K : Any, V : Any> {
*/
suspend fun configSet(parameter: String, value: String): String?

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: `OK` when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
suspend fun configSet(kvs: Map<String, String>): String?

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ internal class RedisServerCoroutinesCommandsImpl<K : Any, V : Any>(internal val

override suspend fun configGet(parameter: String): Map<String, String>? = ops.configGet(parameter).awaitFirstOrNull()

override suspend fun configGet(vararg parameters: String): Map<String, String>? = ops.configGet(*parameters).awaitFirstOrNull()

override suspend fun configResetstat(): String? = ops.configResetstat().awaitFirstOrNull()

override suspend fun configRewrite(): String? = ops.configRewrite().awaitFirstOrNull()

override suspend fun configSet(parameter: String, value: String): String? = ops.configSet(parameter, value).awaitFirstOrNull()

override suspend fun configSet(kvs: Map<String, String>): String? = ops.configSet(kvs).awaitFirstOrNull()

override suspend fun dbsize(): Long? = ops.dbsize().awaitFirstOrNull()

override suspend fun debugCrashAndRecover(delay: Long): String? = ops.debugCrashAndRecover(delay).awaitFirstOrNull()
Expand Down
18 changes: 18 additions & 0 deletions src/main/templates/io/lettuce/core/api/RedisServerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ public interface RedisServerCommands<K, V> {
*/
Map<String, String> configGet(String parameter);

/**
* Get the value of multiple pattern parameters.
*
* @param parameters patterns names of Redis server's configuration.
* @return Map&lt;String, String&gt; bulk-string-reply.
* @since 7.0
*/
Map<String, String> configGet(String... parameters);

/**
* Reset the stats returned by INFO.
*
Expand All @@ -204,6 +213,15 @@ public interface RedisServerCommands<K, V> {
*/
String configSet(String parameter, String value);

/**
* Set multiple parameters to the given value.
*
* @param kvs the parameter name and value.
* @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned.
* @since 7.0
*/
String configSet(Map<String, String> kvs);

/**
* Return the number of keys in the selected database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static org.junit.jupiter.api.Assumptions.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -319,6 +321,13 @@ void configGet() {
assertThat(redis.configGet("maxmemory")).containsEntry("maxmemory", "0");
}

@Test
@EnabledOnCommand("EVAL_RO") // Redis 7.0
void configGetMultipleParameters() {
assertThat(redis.configGet("maxmemory", "*max-*-entries*")).containsEntry("maxmemory", "0")
.containsEntry("hash-max-listpack-entries", "512");
}

@Test
void configResetstat() {
redis.get(key);
Expand All @@ -335,6 +344,19 @@ void configSet() {
redis.configSet("maxmemory", maxmemory);
}

@Test
@EnabledOnCommand("EVAL_RO") // Redis 7.0
void configSetMultipleParameters() {
Map<String, String> original = redis.configGet("maxmemory", "hash-max-listpack-entries");
Map<String, String> config = new HashMap<>();
config.put("maxmemory", "1024");
config.put("hash-max-listpack-entries", "1024");
assertThat(redis.configSet(config)).isEqualTo("OK");
assertThat(redis.configGet("maxmemory", "hash-max-listpack-entries")).containsAllEntriesOf(config);
// recover
redis.configSet(original);
}

@Test
void configRewrite() {

Expand Down