diff --git a/redis/commands/core.py b/redis/commands/core.py index 5074e8064d..1e221c9402 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -28,6 +28,14 @@ def acl_cat(self, category=None, **kwargs): pieces = [category] if category else [] return self.execute_command("ACL CAT", *pieces, **kwargs) + def acl_dryrun(self, username, *args, **kwargs): + """ + Simulate the execution of a given command by a given ``username``. + + For more information check https://redis.io/commands/acl-dryrun + """ + return self.execute_command("ACL DRYRUN", username, *args, **kwargs) + def acl_deluser(self, *username, **kwargs): """ Delete the ACL for the specified ``username``s diff --git a/tests/test_commands.py b/tests/test_commands.py index 0e27836b05..ad9ee2c5fd 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -87,6 +87,19 @@ def test_acl_cat_with_category(self, r): assert isinstance(commands, list) assert "get" in commands + @skip_if_server_version_lt("7.0.0") + def test_acl_dryrun(self, r): + username = "redis-py-user" + r.acl_setuser( + username, + keys=["*"], + commands=["+set"], + ) + assert r.acl_dryrun(username, "set", "key", "value") == b"OK" + assert r.acl_dryrun(username, "get", "key").startswith( + b"This user has no permissions to run the" + ) + @skip_if_server_version_lt("6.0.0") @skip_if_redis_enterprise() def test_acl_deluser(self, r, request):