-
Notifications
You must be signed in to change notification settings - Fork 554
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
Add max_delay for every reconnect #1192
Closed
tonynguyen-sotatek
wants to merge
1
commit into
redis-rs:main
from
tonynguyen-sotatek:Add_max_delay_field_is_time_max_wait_max_every_reconnect
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,9 @@ pub struct ConnectionInfo { | |
|
||
/// A boxed connection address for where to connect to. | ||
pub redis: RedisConnectionInfo, | ||
|
||
/// In case of reconnection issues, the manager will retry reconnection | ||
pub retry_strategy: Option<RetryStrategyInfo>, | ||
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. this isn't the place for this - if only one connection type uses this, it should be in that type's config, not here. |
||
} | ||
|
||
/// Redis specific/connection independent information used to establish a connection to redis. | ||
|
@@ -226,6 +229,21 @@ pub struct RedisConnectionInfo { | |
pub protocol: ProtocolVersion, | ||
} | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct RetryStrategyInfo { | ||
/// The resulting duration is calculated by taking the base to the `n`-th power, | ||
/// where `n` denotes the number of past attempts. | ||
pub exponent_base: Option<u64>, | ||
/// A multiplicative factor that will be applied to the retry delay. | ||
/// | ||
/// For example, using a factor of `1000` will make each delay in units of seconds. | ||
pub factor: Option<u64>, | ||
/// number_of_retries times, with an exponentially increasing delay | ||
pub number_of_retries: Option<usize>, | ||
/// Apply a maximum delay. No retry delay will be longer than this `Duration`. | ||
pub max_delay: Option<u64>, | ||
} | ||
|
||
impl FromStr for ConnectionInfo { | ||
type Err = RedisError; | ||
|
||
|
@@ -273,6 +291,7 @@ where | |
Ok(ConnectionInfo { | ||
addr: ConnectionAddr::Tcp(self.0.into(), self.1), | ||
redis: RedisConnectionInfo::default(), | ||
retry_strategy: None, | ||
}) | ||
} | ||
} | ||
|
@@ -390,6 +409,7 @@ fn url_to_tcp_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> { | |
_ => ProtocolVersion::RESP2, | ||
}, | ||
}, | ||
retry_strategy: None, | ||
}) | ||
} | ||
|
||
|
@@ -421,6 +441,7 @@ fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> { | |
_ => ProtocolVersion::RESP2, | ||
}, | ||
}, | ||
retry_strategy: None, | ||
}) | ||
} | ||
|
||
|
@@ -1443,7 +1464,7 @@ where | |
/// | ||
/// ```rust,no_run | ||
/// # fn do_something() -> redis::RedisResult<()> { | ||
/// let client = redis::Client::open("redis://127.0.0.1/")?; | ||
/// let client = redis::Client::open("redis://127.0.0.1/", None)?; | ||
/// let mut con = client.get_connection()?; | ||
/// let mut pubsub = con.as_pubsub(); | ||
/// pubsub.subscribe("channel_1")?; | ||
|
@@ -1673,7 +1694,7 @@ impl Msg { | |
/// ```rust,no_run | ||
/// use redis::Commands; | ||
/// # fn do_something() -> redis::RedisResult<()> { | ||
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap(); | ||
/// # let client = redis::Client::open("redis://127.0.0.1/", None).unwrap(); | ||
/// # let mut con = client.get_connection().unwrap(); | ||
/// let key = "the_key"; | ||
/// let (new_val,) : (isize,) = redis::transaction(&mut con, &[key], |con, pipe| { | ||
|
@@ -1791,13 +1812,15 @@ mod tests { | |
ConnectionInfo { | ||
addr: ConnectionAddr::Tcp("127.0.0.1".to_string(), 6379), | ||
redis: Default::default(), | ||
retry_strategy: None, | ||
}, | ||
), | ||
( | ||
url::Url::parse("redis://[::1]").unwrap(), | ||
ConnectionInfo { | ||
addr: ConnectionAddr::Tcp("::1".to_string(), 6379), | ||
redis: Default::default(), | ||
retry_strategy: None, | ||
}, | ||
), | ||
( | ||
|
@@ -1810,6 +1833,7 @@ mod tests { | |
password: Some("#@<>$".to_string()), | ||
..Default::default() | ||
}, | ||
retry_strategy: None, | ||
}, | ||
), | ||
]; | ||
|
@@ -1877,6 +1901,7 @@ mod tests { | |
password: None, | ||
protocol: ProtocolVersion::RESP2, | ||
}, | ||
retry_strategy: None, | ||
}, | ||
), | ||
( | ||
|
@@ -1887,6 +1912,7 @@ mod tests { | |
db: 1, | ||
..Default::default() | ||
}, | ||
retry_strategy: None, | ||
}, | ||
), | ||
( | ||
|
@@ -1902,6 +1928,7 @@ mod tests { | |
password: Some("#@<>$".to_string()), | ||
..Default::default() | ||
}, | ||
retry_strategy: None, | ||
}, | ||
), | ||
( | ||
|
@@ -1917,6 +1944,7 @@ mod tests { | |
password: Some("&?= *+".to_string()), | ||
..Default::default() | ||
}, | ||
retry_strategy: None, | ||
}, | ||
), | ||
]; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
instead of adding another field to the function, which is a breaking change, you should add another function taking that field.
and in order to limit the number of functions, please follow the example in this PR - that is, add a configuration object, and a function using that configuration object, so that new fields won't break users.
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.
Thank you, i will update code with new PR