-
Notifications
You must be signed in to change notification settings - Fork 535
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
settings for redis sentinel #3266
Changes from 1 commit
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 |
---|---|---|
|
@@ -287,9 +287,28 @@ def str_to_bool(s: str) -> bool: | |
} | ||
}) | ||
|
||
REDIS_MASTER_IP = None | ||
REDIS_MASTER_PORT = None | ||
|
||
REDIS_SENTINEL_ENABLED = os.environ.get('REDIS_SENTINEL_ENABLED', 'false').lower() == 'true' # noqa: E501 | ||
if REDIS_SENTINEL_ENABLED: | ||
from redis.sentinel import Sentinel | ||
|
||
# SENTINEL_HOSTS env variable format: host_1:port;host_2:port | ||
SENTINEL_HOSTS = os.environ['SENTINEL_HOSTS'].split(';') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider naming it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
REDIS_CLUSTER_NAME = os.environ['REDIS_CLUSTER_NAME'] | ||
|
||
sentinel = Sentinel( | ||
[tuple(s_host.split(':')) for s_host in SENTINEL_HOSTS], | ||
socket_timeout=0.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be better allow to parameterize this timeout as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
) | ||
REDIS_MASTER_IP, REDIS_MASTER_PORT = sentinel.discover_master( | ||
REDIS_CLUSTER_NAME | ||
) | ||
|
||
REDIS_CONNECTION = { | ||
'HOST': os.environ.get('REDIS_HOST', 'localhost'), | ||
'PORT': os.environ.get('REDIS_PORT', '6379'), | ||
'HOST': REDIS_MASTER_IP if REDIS_MASTER_IP else os.environ.get('REDIS_HOST', 'localhost'), # noqa: E501 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, |
||
'PORT': REDIS_MASTER_PORT if REDIS_MASTER_PORT else os.environ.get('REDIS_PORT', '6379'), # noqa: E501 | ||
'DB': int(os.environ.get('REDIS_DB', 0)), | ||
'PASSWORD': os.environ.get('REDIS_PASSWORD', ''), | ||
# timeout for executing commands | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
str_to_bool
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok