Skip to content

Support for SCRIPT FLUSH with SYNC/ASYNC #1567

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

Merged
merged 1 commit into from
Sep 1, 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
14 changes: 11 additions & 3 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions tests/test_scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down