Skip to content

Conversation

@vchomakov
Copy link

Description

Adds support for redis-py's DriverInfo class to identify fastapi-cache as an upstream driver in Redis connection metadata, following the Redis client library identification guidance.

This improves observability for Redis administrators by making fastapi-cache connections easily identifiable when inspecting connected clients (e.g., via CLIENT LIST or CLIENT INFO commands).

Changes

  • Add _add_driver_info() method to RedisBackend class
  • Use DriverInfo class when available
  • Fallback to lib_name/lib_version for older redis-py versions
  • Add comprehensive unit tests in tests/test_redis_backend.py

Motivation

Redis recommends that client libraries identify themselves using CLIENT SETINFO to help administrators understand which applications are connected. This change aligns fastapi-cache with this best practice by:

  • Setting lib-name to identify fastapi-cache as the upstream driver (e.g., redis-py(fastapi-cache_v0.2.2))
  • Setting lib-ver to the redis-py client version
  • Making fastapi-cache connections distinguishable from other redis-py users

Compatibility

The implementation gracefully handles different redis-py versions:

  • Modern redis-py: Uses DriverInfo class (preferred method)
  • Older redis-py: Uses lib_name/lib_version fallback

Testing

  • Added 7 unit tests covering all code paths
  • All existing tests pass
  • Gracefully handles missing connection pools and unknown redis-py versions

@vchomakov vchomakov marked this pull request as ready for review January 8, 2026 12:23
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.

1 participant