Skip to content
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

Pre 6.2 redis should default to None for script flush #1641

Merged
merged 2 commits into from
Oct 25, 2021
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
16 changes: 11 additions & 5 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,16 +2922,22 @@ def script_debug(self, *args):
"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 "
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean >=?

"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):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def test_script_flush(self, r):
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)
Expand Down