Add CACHE_ENABLED env var to toggle Redis caching (v2.2.1)
- Set CACHE_ENABLED=false to disable caching without stopping Redis - Defaults to true (caching enabled) - Useful for draft periods requiring real-time data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
254ce2ddc5
commit
e6a325ac8f
@ -26,23 +26,28 @@ logger = logging.getLogger('discord_app')
|
|||||||
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
|
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
|
||||||
REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379'))
|
REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379'))
|
||||||
REDIS_DB = int(os.environ.get('REDIS_DB', '0'))
|
REDIS_DB = int(os.environ.get('REDIS_DB', '0'))
|
||||||
|
CACHE_ENABLED = os.environ.get('CACHE_ENABLED', 'true').lower() == 'true'
|
||||||
|
|
||||||
# Initialize Redis client with connection error handling
|
# Initialize Redis client with connection error handling
|
||||||
try:
|
if not CACHE_ENABLED:
|
||||||
redis_client = Redis(
|
logger.info("Caching disabled via CACHE_ENABLED=false")
|
||||||
host=REDIS_HOST,
|
|
||||||
port=REDIS_PORT,
|
|
||||||
db=REDIS_DB,
|
|
||||||
decode_responses=True,
|
|
||||||
socket_connect_timeout=5,
|
|
||||||
socket_timeout=5
|
|
||||||
)
|
|
||||||
# Test connection
|
|
||||||
redis_client.ping()
|
|
||||||
logger.info(f"Redis connected successfully at {REDIS_HOST}:{REDIS_PORT}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Redis connection failed: {e}. Caching will be disabled.")
|
|
||||||
redis_client = None
|
redis_client = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
redis_client = Redis(
|
||||||
|
host=REDIS_HOST,
|
||||||
|
port=REDIS_PORT,
|
||||||
|
db=REDIS_DB,
|
||||||
|
decode_responses=True,
|
||||||
|
socket_connect_timeout=5,
|
||||||
|
socket_timeout=5
|
||||||
|
)
|
||||||
|
# Test connection
|
||||||
|
redis_client.ping()
|
||||||
|
logger.info(f"Redis connected successfully at {REDIS_HOST}:{REDIS_PORT}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Redis connection failed: {e}. Caching will be disabled.")
|
||||||
|
redis_client = None
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
priv_help = False if not os.environ.get('PRIVATE_IN_SCHEMA') else os.environ.get('PRIVATE_IN_SCHEMA').upper()
|
priv_help = False if not os.environ.get('PRIVATE_IN_SCHEMA') else os.environ.get('PRIVATE_IN_SCHEMA').upper()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user