summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-10-25 13:41:06 +0300
committerGitHub <noreply@github.com>2021-10-25 13:41:06 +0300
commit0ef4c0711693b4b313ce97261214bd151d8261d5 (patch)
tree58887c0873fca123f47066608bcc02ff761e8273
parent36e00ec4e22a9f947e099affdfdc79862ac7ca08 (diff)
downloadredis-py-0ef4c0711693b4b313ce97261214bd151d8261d5.tar.gz
Pre 6.2 redis should default to None for script flush (#1641)
-rw-r--r--redis/commands.py16
-rw-r--r--tests/test_scripting.py4
2 files changed, 15 insertions, 5 deletions
diff --git a/redis/commands.py b/redis/commands.py
index f5243e4..2697e78 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -2922,16 +2922,22 @@ class Commands:
"SCRIPT DEBUG is intentionally not implemented in the client."
)
- def script_flush(self, sync_type="SYNC"):
+ def script_flush(self, sync_type=None):
"""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]
+
+ # Redis pre 6 had no sync_type.
+ if sync_type not in ["SYNC", "ASYNC", None]:
+ raise DataError("SCRIPT FLUSH defaults to SYNC in redis > 6.2, or "
+ "accepts SYNC/ASYNC. For older versions, "
+ "of redis leave as None.")
+ if sync_type is None:
+ pieces = []
+ else:
+ pieces = [sync_type]
return self.execute_command('SCRIPT FLUSH', *pieces)
def script_kill(self):
diff --git a/tests/test_scripting.py b/tests/test_scripting.py
index cc67e26..c3c2094 100644
--- a/tests/test_scripting.py
+++ b/tests/test_scripting.py
@@ -43,6 +43,10 @@ class TestScripting:
r.script_load(multiply_script)
r.script_flush()
+ r.set('a', 2)
+ r.script_load(multiply_script)
+ r.script_flush(None)
+
with pytest.raises(exceptions.DataError):
r.set('a', 2)
r.script_load(multiply_script)