Skip to content

Commit

Permalink
Update to match redis 6.0.6+ handling exec failures
Browse files Browse the repository at this point in the history
They now map plain errors into EXECABORT. This should keep Travis happy
again.
  • Loading branch information
bmerry committed Feb 15, 2021
1 parent 541c91a commit f2a4018
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -96,7 +96,7 @@ your error handling. Simply set the connected attribute of the server to
Fakeredis implements the same interface as `redis-py`_, the
popular redis client for python, and models the responses
of redis 5.0.
of redis 6.0 (although most new feature in 6.0 are not supported).

Support for aioredis
====================
Expand Down
3 changes: 3 additions & 0 deletions fakeredis/_server.py
Expand Up @@ -815,6 +815,7 @@ def sendall(self, data):
def _process_command(self, fields):
if not fields:
return
func_name = None
try:
func, func_name = self._name_to_func(fields[0])
sig = func._fakeredis_sig
Expand All @@ -835,6 +836,8 @@ def _process_command(self, fields):
# TODO: should not apply if the exception is from _run_command
# e.g. watch inside multi
self._transaction_failed = True
if func_name == 'exec' and exc.value.startswith('ERR '):
exc.value = 'EXECABORT Transaction discarded because of: ' + exc.value[4:]
result = exc
result = self._decode_result(result)
if not isinstance(result, NoResponse):
Expand Down
8 changes: 8 additions & 0 deletions test/test_fakeredis.py
Expand Up @@ -3382,6 +3382,14 @@ def test_pipeline_move(r):
p.execute()


@pytest.mark.min_server('6.0.6')
def test_exec_bad_arguments(r):
# Redis 6.0.6 changed the behaviour of exec so that it always fails with
# EXECABORT, even when it's just bad syntax.
with pytest.raises(redis.exceptions.ExecAbortError):
r.execute_command('exec', 'blahblah')


def test_key_patterns(r):
r.mset({'one': 1, 'two': 2, 'three': 3, 'four': 4})
assert sorted(r.keys('*o*')) == [b'four', b'one', b'two']
Expand Down

0 comments on commit f2a4018

Please sign in to comment.