Skip to content

Commit

Permalink
Pre 6.2 redis should default to None for script flush (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored Oct 25, 2021
1 parent 36e00ec commit 0ef4c07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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 "
"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

0 comments on commit 0ef4c07

Please sign in to comment.