summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-09-01 17:31:55 +0300
committerGitHub <noreply@github.com>2021-09-01 17:31:55 +0300
commite9837c1d6360d27fac0d8fed6384fd9b2b568b5c (patch)
tree5c50d4995122b9893a3ab68b637362067b6fd70f
parent42a050c6c0d120104c7433e825e7a798ba411e55 (diff)
downloadredis-py-e9837c1d6360d27fac0d8fed6384fd9b2b568b5c.tar.gz
Support for SCRIPT FLUSH with SYNC/ASYNC (#1567)
Part of #1546
-rw-r--r--redis/commands.py14
-rw-r--r--tests/test_scripting.py18
2 files changed, 29 insertions, 3 deletions
diff --git a/redis/commands.py b/redis/commands.py
index 7f7e00f..5f1f57b 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -2786,9 +2786,17 @@ class Commands:
"""
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 02c0f17..cc67e26 100644
--- a/tests/test_scripting.py
+++ b/tests/test_scripting.py
@@ -30,6 +30,24 @@ class TestScripting:
# 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)