Skip to content

CONFIG SET - add the ability to set multiple parameters in one call #2143

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

Merged
merged 2 commits into from
Apr 27, 2022
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
10 changes: 8 additions & 2 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,18 @@ def config_get(
"""
return self.execute_command("CONFIG GET", pattern, *args, **kwargs)

def config_set(self, name: KeyT, value: EncodableT, **kwargs) -> ResponseT:
def config_set(
self,
name: KeyT,
value: EncodableT,
*args: List[Union[KeyT, EncodableT]],
**kwargs,
) -> ResponseT:
"""Set config item ``name`` with ``value``

For more information see https://redis.io/commands/config-set
"""
return self.execute_command("CONFIG SET", name, value, **kwargs)
return self.execute_command("CONFIG SET", name, value, *args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean.


def config_resetstat(self, **kwargs) -> ResponseT:
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,16 @@ def test_config_set(self, r):
assert r.config_set("timeout", 0)
assert r.config_get()["timeout"] == "0"

@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
def test_config_set_multi_params(self, r: redis.Redis):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a lazy, future option for writing tests like this (psuedocode). It comes from a pattern used in go:

x = [('timeout', 70), ('maxmemory', 100)]
r.config_set(*x)
for y in x:
    assert r.config_get(x[0]) == x[1]

r.config_set("timeout", 70, "maxmemory", 100)
assert r.config_get()["timeout"] == "70"
assert r.config_get()["maxmemory"] == "100"
assert r.config_set("timeout", 0, "maxmemory", 0)
assert r.config_get()["timeout"] == "0"
assert r.config_get()["maxmemory"] == "0"

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise()
def test_failover(self, r):
Expand Down