Skip to content
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

common: make get_redis_connection to accept dict(opts) #3186

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions common/copr_common/redis_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ def get_redis_connection(opts):
:rtype: StrictRedis
"""
kwargs = {}
if hasattr(opts, "redis_db"):
kwargs["db"] = opts.redis_db
if hasattr(opts, "redis_host"):
kwargs["host"] = opts.redis_host
if hasattr(opts, "redis_port"):
kwargs["port"] = opts.redis_port
if hasattr(opts, "redis_password"):
kwargs["password"] = opts.redis_password
for key in ["db", "host", "port", "password"]:
config_key = "redis_" + key

# dict-like objects
if isinstance(opts, dict):
if config_key in opts:
kwargs[key] = opts[config_key]
continue

# class-like objects
if hasattr(opts, config_key):
kwargs[key] = getattr(opts, config_key)
continue

return StrictRedis(encoding="utf-8", decode_responses=True, **kwargs)