Skip to content

feat: add Redis driver info for client identification#95

Open
vchomakov wants to merge 1 commit intopermitio:masterfrom
vchomakov:feature/redis-driver-info
Open

feat: add Redis driver info for client identification#95
vchomakov wants to merge 1 commit intopermitio:masterfrom
vchomakov:feature/redis-driver-info

Conversation

@vchomakov
Copy link

Description

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

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

Changes

  • Add _add_driver_info_to_broadcast() method to EventBroadcaster class
  • Use DriverInfo class when available (modern redis-py)
  • Fallback to lib_name/lib_version for older redis-py versions
  • Add comprehensive unit tests in tests/test_driver_info.py

Motivation

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

  • Setting lib-name to identify fastapi-websocket-pubsub as the upstream driver (e.g., redis-py(fastapi-websocket-pubsub_v0.3.9))
  • Setting lib-ver to the redis-py client version
  • Making fastapi-websocket-pubsub 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
  • Non-Redis backends: Safely skips driver info injection

Testing

  • Added 5 unit tests covering all code paths
  • All existing tests pass
  • Gracefully handles missing connection pools and non-Redis backends

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