-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: ✨ client connection options #534
Conversation
using options pattern redis client connection options closes #529
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.
Yes works great ✨!
I've added a suggestion for the Tile38
interface, but either way works for me.
pyle38/tile38.py
Outdated
def __init__( | ||
self, | ||
url=os.getenv("TILE38_LEADER_URI"), | ||
follower_url=os.getenv("TILE38_FOLLOWER_URI"), | ||
*opts: Callable[..., ClientOptions], |
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.
Having the options as *args
makes the client interface a bit clunky as you can no longer use the key word args for url
and follower_url
and pass a list of options.
# Doesn't work
tile38 = Tile38(
url="redis://localhost:9851",
WithRetryExponentialBackoff(30),
WithRetryOnError(Pyle38TimeoutError, Pyle38ConnectionError),
)
You can of course expand them inline,
tile38 = Tile38(
url="redis://localhost:9851",
*[
WithRetryExponentialBackoff(30),
WithRetryOnError(Pyle38TimeoutError, Pyle38ConnectionError),
]
)
but I think having another key word argument feels nicer?
*opts: Callable[..., ClientOptions], | |
options: List[Callable[..., ClientOptions]] = None, |
And then of course:
def __init__(
self,
url=os.getenv("TILE38_LEADER_URI"),
follower_url=os.getenv("TILE38_FOLLOWER_URI"),
options: List[Callable[..., ClientOptions]] = None,
):
if not url:
raise Tile38Error("No Tile38 url set")
if options is None:
options = []
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.
Yeah my thoughts exactly. The way it is now is a little too golang’ish. Although I don’t like array as inputs either. .. unless I’m changing that follower_url as well. 😈
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.
im going for a less disruptive option. ill take on the follower refactor when I add the option for multiple follower instances.
@alxwrd
using options pattern redis client connection options. options pattern doesn't seem to be too widely used, yet it allows me to abstract away any of the redis retry and backoff implementations. the final version might look a little different, but I think you can test run this one to see if that suffices to close #529.
closes #529
UPDATE:
run
start this in one terminal
in another terminal restart the tile38 leader
as long as the leader comes back on within those 25 retries, the ConnectionError will not be raised.