Skip to content

Commit e9837c1

Browse files
authored
Support for SCRIPT FLUSH with SYNC/ASYNC (#1567)
Part of #1546
1 parent 42a050c commit e9837c1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

redis/commands.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -2786,9 +2786,17 @@ def script_exists(self, *args):
27862786
"""
27872787
return self.execute_command('SCRIPT EXISTS', *args)
27882788

2789-
def script_flush(self):
2790-
"Flush all scripts from the script cache"
2791-
return self.execute_command('SCRIPT FLUSH')
2789+
def script_flush(self, sync_type="SYNC"):
2790+
"""Flush all scripts from the script cache.
2791+
``sync_type`` is by default SYNC (synchronous) but it can also be
2792+
ASYNC.
2793+
See: https://redis.io/commands/script-flush
2794+
"""
2795+
if sync_type not in ["SYNC", "ASYNC"]:
2796+
raise DataError("SCRIPT FLUSH defaults to SYNC or"
2797+
"accepts SYNC/ASYNC")
2798+
pieces = [sync_type]
2799+
return self.execute_command('SCRIPT FLUSH', *pieces)
27922800

27932801
def script_kill(self):
27942802
"Kill the currently executing Lua script"

tests/test_scripting.py

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ def test_eval(self, r):
3030
# 2 * 3 == 6
3131
assert r.eval(multiply_script, 1, 'a', 3) == 6
3232

33+
def test_script_flush(self, r):
34+
r.set('a', 2)
35+
r.script_load(multiply_script)
36+
r.script_flush('ASYNC')
37+
38+
r.set('a', 2)
39+
r.script_load(multiply_script)
40+
r.script_flush('SYNC')
41+
42+
r.set('a', 2)
43+
r.script_load(multiply_script)
44+
r.script_flush()
45+
46+
with pytest.raises(exceptions.DataError):
47+
r.set('a', 2)
48+
r.script_load(multiply_script)
49+
r.script_flush("NOTREAL")
50+
3351
def test_evalsha(self, r):
3452
r.set('a', 2)
3553
sha = r.script_load(multiply_script)

0 commit comments

Comments
 (0)