unistore-retry

Crates.iounistore-retry
lib.rsunistore-retry
version0.1.0
created_at2026-01-20 11:04:07.615888+00
updated_at2026-01-20 11:04:07.615888+00
descriptionRetry strategy capability for UniStore
homepagehttps://github.com/yangbo1317/unistore
repositoryhttps://github.com/yangbo1317/unistore
max_upload_size
id2056357
size36,100
(yangbo1317)

documentation

https://docs.rs/unistore-retry

README

unistore-retry

重试策略能力 - UniStore 能力生态的一部分。

功能特性

  • 多种策略: 固定间隔、指数退避、线性递增
  • 抖动支持: 防止惊群效应
  • 可重试判断: 自定义哪些错误应该重试
  • 异步友好: 完美支持 async/await
  • 详细报告: 提供重试统计和历史

快速开始

use unistore_retry::{retry, ExponentialBackoff};

// 使用指数退避重试
let result = retry(ExponentialBackoff::default(), || async {
    fetch_data_from_api().await
}).await;

自定义策略

use unistore_retry::{RetryPolicy, RetryConfig};

let policy = RetryPolicy::exponential()
    .max_retries(5)
    .initial_delay(Duration::from_millis(100))
    .max_delay(Duration::from_secs(30))
    .jitter(0.1);

let result = policy.execute(|| async {
    unreliable_operation().await
}).await;

条件重试

use unistore_retry::{retry_if, ExponentialBackoff};

let result = retry_if(
    ExponentialBackoff::default(),
    || async { api_call().await },
    |err| err.is_retryable(),  // 只重试特定错误
).await;

License

MIT OR Apache-2.0

Commit count: 0

cargo fmt