diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index 6304cbc798..7819883cf5 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -511,6 +511,11 @@ public RedisFuture> configGet(String parameter) { return dispatch(commandBuilder.configGet(parameter)); } + @Override + public RedisFuture> configGet(String... parameters) { + return dispatch(commandBuilder.configGet(parameters)); + } + @Override public RedisFuture configResetstat() { return dispatch(commandBuilder.configResetstat()); @@ -526,6 +531,11 @@ public RedisFuture configSet(String parameter, String value) { return dispatch(commandBuilder.configSet(parameter, value)); } + @Override + public RedisFuture configSet(Map kvs) { + return dispatch(commandBuilder.configSet(kvs)); + } + @Override public RedisFuture dbsize() { return dispatch(commandBuilder.dbsize()); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index b5a9b1d44c..276fe7bee2 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -531,6 +531,11 @@ public Mono> configGet(String parameter) { return createMono(() -> commandBuilder.configGet(parameter)); } + @Override + public Mono> configGet(String... parameters) { + return createMono(() -> commandBuilder.configGet(parameters)); + } + @Override public Mono configResetstat() { return createMono(commandBuilder::configResetstat); @@ -546,6 +551,11 @@ public Mono configSet(String parameter, String value) { return createMono(() -> commandBuilder.configSet(parameter, value)); } + @Override + public Mono configSet(Map kvs) { + return createMono(() -> commandBuilder.configSet(kvs)); + } + @SuppressWarnings("unchecked") public Flux createDissolvingFlux(Supplier> commandSupplier) { return (Flux) createFlux(commandSupplier, true); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 0f6b96e9eb..087f60253c 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -695,6 +695,17 @@ Command> configGet(String parameter) { return createCommand(CONFIG, new MapOutput<>((RedisCodec) StringCodec.UTF8), args); } + Command> configGet(String... parameters) { + LettuceAssert.notNull(parameters, "Parameters " + MUST_NOT_BE_NULL); + LettuceAssert.notEmpty(parameters, "Parameters " + MUST_NOT_BE_EMPTY); + + CommandArgs 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 configResetstat() { CommandArgs args = new CommandArgs<>(codec).add(RESETSTAT); return createCommand(CONFIG, new StatusOutput<>(codec), args); @@ -714,6 +725,18 @@ Command configSet(String parameter, String value) { return createCommand(CONFIG, new StatusOutput<>(codec), args); } + Command configSet(Map configValues) { + LettuceAssert.notNull(configValues, "ConfigValues " + MUST_NOT_BE_NULL); + LettuceAssert.isTrue(!configValues.isEmpty(), "ConfigValues " + MUST_NOT_BE_EMPTY); + + CommandArgs args = new CommandArgs<>(codec).add(SET); + configValues.forEach((parameter, value) -> { + args.add(parameter); + args.add(value); + }); + return createCommand(CONFIG, new StatusOutput<>(codec), args); + } + Command dbsize() { return createCommand(DBSIZE, new IntegerOutput<>(codec)); } diff --git a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java index 27ed0f041f..67c9c81e85 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java @@ -183,6 +183,15 @@ public interface RedisServerAsyncCommands { */ RedisFuture> configGet(String parameter); + /** + * 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 + */ + RedisFuture> configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -207,6 +216,15 @@ public interface RedisServerAsyncCommands { */ RedisFuture 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 configSet(Map kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java index 826e45aeb5..50b03e9d53 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java @@ -183,6 +183,15 @@ public interface RedisServerReactiveCommands { */ Mono> configGet(String parameter); + /** + * 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 + */ + Mono> configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -207,6 +216,15 @@ public interface RedisServerReactiveCommands { */ Mono 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 configSet(Map kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java index 09cdb7a586..cfa2b1dfe9 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java @@ -182,6 +182,15 @@ public interface RedisServerCommands { */ Map configGet(String parameter); + /** + * 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 + */ + Map configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -206,6 +215,15 @@ public interface RedisServerCommands { */ 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 kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java index c52c802d03..60aa62ccdc 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java @@ -181,6 +181,15 @@ public interface NodeSelectionServerAsyncCommands { */ AsyncExecutions> configGet(String parameter); + /** + * 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 + */ + AsyncExecutions> configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -205,6 +214,15 @@ public interface NodeSelectionServerAsyncCommands { */ AsyncExecutions 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 configSet(Map kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java index 260e144ecf..39d690f15f 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java @@ -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. @@ -181,6 +181,15 @@ public interface NodeSelectionServerCommands { */ Executions> configGet(String parameter); + /** + * 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 + */ + Executions> configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -205,6 +214,15 @@ public interface NodeSelectionServerCommands { */ Executions 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 configSet(Map kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt index 21dbe8fdc8..81e651f334 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt @@ -177,6 +177,15 @@ interface RedisServerCoroutinesCommands { */ suspend fun configGet(parameter: String): Map? + /** + * Get the value of multiple pattern parameters. + * + * @param parameters patterns names of Redis server's configuration. + * @return Map bulk-string-reply. + * @since 7.0 + */ + suspend fun configGet(vararg parameters: String): Map? + /** * Reset the stats returned by INFO. * @@ -201,6 +210,15 @@ interface RedisServerCoroutinesCommands { */ 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? + /** * Return the number of keys in the selected database. * diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommandsImpl.kt index 4ca5b6dee8..ab35a37bf2 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommandsImpl.kt @@ -74,12 +74,16 @@ internal class RedisServerCoroutinesCommandsImpl(internal val override suspend fun configGet(parameter: String): Map? = ops.configGet(parameter).awaitFirstOrNull() + override suspend fun configGet(vararg parameters: String): Map? = 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? = ops.configSet(kvs).awaitFirstOrNull() + override suspend fun dbsize(): Long? = ops.dbsize().awaitFirstOrNull() override suspend fun debugCrashAndRecover(delay: Long): String? = ops.debugCrashAndRecover(delay).awaitFirstOrNull() diff --git a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java index 75b8de57af..9785d7b2f2 100644 --- a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java @@ -180,6 +180,15 @@ public interface RedisServerCommands { */ Map configGet(String parameter); + /** + * 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 + */ + Map configGet(String... parameters); + /** * Reset the stats returned by INFO. * @@ -204,6 +213,15 @@ public interface RedisServerCommands { */ 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 kvs); + /** * Return the number of keys in the selected database. * diff --git a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java index 67b97e842b..1c4dc1d7c9 100644 --- a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java @@ -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; @@ -322,6 +324,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); @@ -338,6 +347,19 @@ void configSet() { redis.configSet("maxmemory", maxmemory); } + @Test + @EnabledOnCommand("EVAL_RO") // Redis 7.0 + void configSetMultipleParameters() { + Map original = redis.configGet("maxmemory", "hash-max-listpack-entries"); + Map 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() {