Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Ensure `REDIS_MAX_CONNECTION` can accept `None` and integer value for default number of connection. [#515](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/515)

### Removed

### Updated
Expand Down
42 changes: 5 additions & 37 deletions stac_fastapi/core/stac_fastapi/core/redis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Optional, Tuple
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

from pydantic import field_validator
from pydantic import Field, field_validator
from pydantic_settings import BaseSettings
from redis import asyncio as aioredis
from redis.asyncio.sentinel import Sentinel
Expand All @@ -21,11 +21,11 @@ class RedisSentinelSettings(BaseSettings):
REDIS_SENTINEL_MASTER_NAME: str = "master"
REDIS_DB: int = 15

REDIS_MAX_CONNECTIONS: int = 10
REDIS_MAX_CONNECTIONS: Optional[int] = None
REDIS_RETRY_TIMEOUT: bool = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. you could extract the common fields from these two Pydantic classes into a parent class that both inherit from

REDIS_DECODE_RESPONSES: bool = True
REDIS_CLIENT_NAME: str = "stac-fastapi-app"
REDIS_HEALTH_CHECK_INTERVAL: int = 30
REDIS_HEALTH_CHECK_INTERVAL: int = Field(default=30, gt=0)
REDIS_SELF_LINK_TTL: int = 1800

@field_validator("REDIS_DB")
Expand All @@ -36,22 +36,6 @@ def validate_db_sentinel(cls, v: int) -> int:
raise ValueError("REDIS_DB must be a positive integer")
return v

@field_validator("REDIS_MAX_CONNECTIONS")
@classmethod
def validate_max_connections_sentinel(cls, v: int) -> int:
"""Validate REDIS_MAX_CONNECTIONS is at least 1."""
if v < 1:
raise ValueError("REDIS_MAX_CONNECTIONS must be at least 1")
return v

@field_validator("REDIS_HEALTH_CHECK_INTERVAL")
@classmethod
def validate_health_check_interval_sentinel(cls, v: int) -> int:
"""Validate REDIS_HEALTH_CHECK_INTERVAL is not negative integer."""
if v < 0:
raise ValueError("REDIS_HEALTH_CHECK_INTERVAL must be a positive integer")
return v

@field_validator("REDIS_SELF_LINK_TTL")
@classmethod
def validate_self_link_ttl_sentinel(cls, v: int) -> int:
Expand Down Expand Up @@ -111,11 +95,11 @@ class RedisSettings(BaseSettings):
REDIS_PORT: int = 6379
REDIS_DB: int = 15

REDIS_MAX_CONNECTIONS: int = 10
REDIS_MAX_CONNECTIONS: Optional[int] = None
REDIS_RETRY_TIMEOUT: bool = True
REDIS_DECODE_RESPONSES: bool = True
REDIS_CLIENT_NAME: str = "stac-fastapi-app"
REDIS_HEALTH_CHECK_INTERVAL: int = 30
REDIS_HEALTH_CHECK_INTERVAL: int = Field(default=30, gt=0)
REDIS_SELF_LINK_TTL: int = 1800

@field_validator("REDIS_PORT")
Expand All @@ -134,22 +118,6 @@ def validate_db_standalone(cls, v: int) -> int:
raise ValueError("REDIS_DB must be a positive integer")
return v

@field_validator("REDIS_MAX_CONNECTIONS")
@classmethod
def validate_max_connections_standalone(cls, v: int) -> int:
"""Validate REDIS_MAX_CONNECTIONS is at least 1."""
if v < 1:
raise ValueError("REDIS_MAX_CONNECTIONS must be at least 1")
return v

@field_validator("REDIS_HEALTH_CHECK_INTERVAL")
@classmethod
def validate_health_check_interval_standalone(cls, v: int) -> int:
"""Validate REDIS_HEALTH_CHECK_INTERVAL is not a negative."""
if v < 0:
raise ValueError("REDIS_HEALTH_CHECK_INTERVAL must be a positive integer")
return v

@field_validator("REDIS_SELF_LINK_TTL")
@classmethod
def validate_self_link_ttl_standalone(cls, v: int) -> int:
Expand Down