diff --git a/redis/commands.py b/redis/commands.py index 7f7e00f2c8..5f1f57b305 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -2786,9 +2786,17 @@ def script_exists(self, *args): """ return self.execute_command('SCRIPT EXISTS', *args) - def script_flush(self): - "Flush all scripts from the script cache" - return self.execute_command('SCRIPT FLUSH') + def script_flush(self, sync_type="SYNC"): + """Flush all scripts from the script cache. + ``sync_type`` is by default SYNC (synchronous) but it can also be + ASYNC. + See: https://redis.io/commands/script-flush + """ + if sync_type not in ["SYNC", "ASYNC"]: + raise DataError("SCRIPT FLUSH defaults to SYNC or" + "accepts SYNC/ASYNC") + pieces = [sync_type] + return self.execute_command('SCRIPT FLUSH', *pieces) def script_kill(self): "Kill the currently executing Lua script" diff --git a/tests/test_scripting.py b/tests/test_scripting.py index 02c0f171d1..cc67e26678 100644 --- a/tests/test_scripting.py +++ b/tests/test_scripting.py @@ -30,6 +30,24 @@ def test_eval(self, r): # 2 * 3 == 6 assert r.eval(multiply_script, 1, 'a', 3) == 6 + def test_script_flush(self, r): + r.set('a', 2) + r.script_load(multiply_script) + r.script_flush('ASYNC') + + r.set('a', 2) + r.script_load(multiply_script) + r.script_flush('SYNC') + + r.set('a', 2) + r.script_load(multiply_script) + r.script_flush() + + with pytest.raises(exceptions.DataError): + r.set('a', 2) + r.script_load(multiply_script) + r.script_flush("NOTREAL") + def test_evalsha(self, r): r.set('a', 2) sha = r.script_load(multiply_script)