Skip to content

Conversation

@leonh
Copy link
Owner

@leonh leonh commented Nov 12, 2025

update the project with up to date dependencies

…edis versions

This update brings the project from 2020-2021 era dependencies to 2024 standards:

Dependencies updated:
- Migrated from deprecated aioredis 1.3.1 to redis 5.0.8 with asyncio support
- Updated FastAPI from 0.65.2 to 0.115.0
- Updated uvicorn from 0.12.1 to 0.30.6
- Updated jinja2 from 2.11.3 (security vulnerabilities) to 3.1.4
- Updated all other dependencies to latest stable versions
- Removed aioredis package (functionality merged into redis)

Code changes:
- Migrated all Redis operations from aioredis 1.x API to redis.asyncio 5.x API
  * Changed from create_redis_pool() to from_url()
  * Updated xread() to use dict-based streams parameter
  * Updated xadd() parameter names (stream→name, message_id→id)
  * Updated xrevrange() parameter names (start/stop→min/max)
  * Changed pool.close() to await pool.aclose()
- Replaced deprecated @app.on_event() lifecycle handlers with lifespan context manager
- Updated error imports from aioredis.errors to redis.exceptions

Infrastructure:
- Updated Dockerfile from Python 3.8 to 3.11
- Updated docker-compose.yml to use Redis 7 instead of 6.0-rc2

Testing: Module imports successfully with no syntax errors
The application was hardcoded to connect to localhost:6379, which doesn't work
in Docker Compose where Redis runs in a separate container.

Changes:
- Updated chat.py to read REDIS_HOST and REDIS_PORT from environment variables
  * Defaults to localhost:6379 for local development
  * Can be overridden for Docker or other deployment scenarios
- Updated docker-compose.yml to set REDIS_HOST=redis for container networking
- Replaced deprecated 'links' with 'depends_on' in docker-compose.yml
- Updated README.md with:
  * Modern Python 3.11+ and Redis 7+ requirements
  * Separate sections for local development and Docker Compose usage
  * Documentation of environment variables

This fixes the "Connection refused" error when running via docker-compose.
The chat message list wasn't updating in real-time because XREAD was using
non-blocking mode, causing it to return immediately without waiting for new
messages.

Root cause:
- XREAD_TIMEOUT = 0 was converted to block=None (non-blocking)
- In old aioredis: timeout=0 meant "block forever"
- In new redis library: block=None means "non-blocking" (return immediately)
- This caused XREAD to constantly poll without waiting for messages

Fix:
- Changed to block=5000 (5 seconds) for proper blocking behavior
- XREAD now waits up to 5 seconds for new messages before returning
- Messages now appear in real-time for all connected users

Tested:
- Users connecting to the same room see each other's messages immediately
- Message list updates within milliseconds of sending
- No more need to refresh or reconnect to see new messages
@leonh leonh merged commit 804b0ec into master Nov 12, 2025
1 check passed
@leonh leonh deleted the claude/test-and-update-project-011CV4pcoMg9pBh6Di4WuPUV branch November 15, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants