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:
Cal Corum 2025-12-10 07:59:54 -06:00
parent 254ce2ddc5
commit e6a325ac8f
2 changed files with 20 additions and 15 deletions

View File

@ -1 +1 @@
2.2.0
2.2.1

View File

@ -26,23 +26,28 @@ logger = logging.getLogger('discord_app')
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379'))
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
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.")
if not CACHE_ENABLED:
logger.info("Caching disabled via CACHE_ENABLED=false")
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")
priv_help = False if not os.environ.get('PRIVATE_IN_SCHEMA') else os.environ.get('PRIVATE_IN_SCHEMA').upper()