-
-
Notifications
You must be signed in to change notification settings - Fork 216
Show host and db in Redis check __repr__ #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,28 @@ class Redis(HealthCheck): | |
| dataclasses.field(repr=False, default=None) | ||
| ) | ||
|
|
||
| def __repr__(self): | ||
| # include client host name and logical database number to identify them | ||
| if self.client_factory is not None: | ||
| client = self.client_factory() | ||
| else: | ||
| # Use the deprecated client parameter (user manages lifecycle) | ||
| client = self.client | ||
|
|
||
| try: | ||
| conn_kwargs = client.connection_pool.connection_kwargs | ||
| host = conn_kwargs["host"] | ||
| db = conn_kwargs["db"] | ||
| return f"Redis(client=RedisClient(host={host}, db={db}))" | ||
| except (AttributeError, KeyError): | ||
| pass | ||
|
|
||
| try: | ||
| hosts = [node.name for node in client.startup_nodes] | ||
| return f"Redis(client=RedisCluster(hosts={hosts!r}))" | ||
| except AttributeError: | ||
| return super().__repr__() | ||
|
codingjoe marked this conversation as resolved.
Comment on lines
+56
to
+76
|
||
|
|
||
|
codingjoe marked this conversation as resolved.
|
||
| def __post_init__(self): | ||
| # Validate that exactly one of client or client_factory is provided | ||
| if self.client is not None and self.client_factory is not None: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.