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

Introduce OutOfMemoryError exception for Redis write command rejections due to OOM errors #2778

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ConnectionError,
DataError,
InvalidResponse,
OutOfMemoryError,
PubSubError,
ReadOnlyError,
RedisError,
Expand Down Expand Up @@ -72,6 +73,7 @@ def int_or_str(value):
"from_url",
"default_backoff",
"InvalidResponse",
"OutOfMemoryError",
"PubSubError",
"ReadOnlyError",
"Redis",
Expand Down
2 changes: 2 additions & 0 deletions redis/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ConnectionError,
DataError,
InvalidResponse,
OutOfMemoryError,
PubSubError,
ReadOnlyError,
RedisError,
Expand All @@ -47,6 +48,7 @@
"default_backoff",
"InvalidResponse",
"PubSubError",
"OutOfMemoryError",
"ReadOnlyError",
"Redis",
"RedisCluster",
Expand Down
2 changes: 2 additions & 0 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
ModuleError,
NoPermissionError,
NoScriptError,
OutOfMemoryError,
ReadOnlyError,
RedisError,
ResponseError,
Expand Down Expand Up @@ -174,6 +175,7 @@ class BaseParser:
"READONLY": ReadOnlyError,
"NOAUTH": AuthenticationError,
"NOPERM": NoPermissionError,
"OOM": OutOfMemoryError,
}

def __init__(self, socket_read_size: int):
Expand Down
2 changes: 2 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ModuleError,
NoPermissionError,
NoScriptError,
OutOfMemoryError,
ReadOnlyError,
RedisError,
ResponseError,
Expand Down Expand Up @@ -149,6 +150,7 @@ class BaseParser:
MODULE_UNLOAD_NOT_POSSIBLE_ERROR: ModuleError,
**NO_AUTH_SET_ERROR,
},
"OOM": OutOfMemoryError,
"WRONGPASS": AuthenticationError,
"EXECABORT": ExecAbortError,
"LOADING": BusyLoadingError,
Expand Down
4 changes: 4 additions & 0 deletions redis/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class NoScriptError(ResponseError):
pass


class OutOfMemoryError(ResponseError):
pass


class ExecAbortError(ResponseError):
pass

Expand Down
10 changes: 9 additions & 1 deletion tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,18 @@ async def test_busy_loading_from_pipeline(self, r):
@skip_if_server_version_lt("2.8.8")
@skip_if_redis_enterprise()
async def test_read_only_error(self, r):
"""READONLY errors get turned in ReadOnlyError exceptions"""
"""READONLY errors get turned into ReadOnlyError exceptions"""
with pytest.raises(redis.ReadOnlyError):
await r.execute_command("DEBUG", "ERROR", "READONLY blah blah")

@skip_if_redis_enterprise()
async def test_oom_error(self, r):
"""OOM errors get turned into OutOfMemoryError exceptions"""
with pytest.raises(redis.OutOfMemoryError):
# note: don't use the DEBUG OOM command since it's not the same
# as the db being full
await r.execute_command("DEBUG", "ERROR", "OOM blah blah")

def test_connect_from_url_tcp(self):
connection = redis.Redis.from_url("redis://localhost")
pool = connection.connection_pool
Expand Down
9 changes: 8 additions & 1 deletion tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,17 @@ def test_busy_loading_from_pipeline(self, r):
@skip_if_server_version_lt("2.8.8")
@skip_if_redis_enterprise()
def test_read_only_error(self, r):
"READONLY errors get turned in ReadOnlyError exceptions"
"READONLY errors get turned into ReadOnlyError exceptions"
with pytest.raises(redis.ReadOnlyError):
r.execute_command("DEBUG", "ERROR", "READONLY blah blah")

def test_oom_error(self, r):
"OOM errors get turned into OutOfMemoryError exceptions"
with pytest.raises(redis.OutOfMemoryError):
# note: don't use the DEBUG OOM command since it's not the same
# as the db being full
r.execute_command("DEBUG", "ERROR", "OOM blah blah")

def test_connect_from_url_tcp(self):
connection = redis.Redis.from_url("redis://localhost")
pool = connection.connection_pool
Expand Down