10 releases

0.2.2 Oct 19, 2024
0.2.1 Oct 6, 2024
0.2.0 Sep 28, 2024
0.1.1 Sep 8, 2024
0.0.8 Aug 25, 2024

#1399 in HTTP server

Download history 117/week @ 2024-08-05 145/week @ 2024-08-12 264/week @ 2024-08-19 36/week @ 2024-08-26 360/week @ 2024-09-02 67/week @ 2024-09-09 42/week @ 2024-09-16 105/week @ 2024-09-23 152/week @ 2024-09-30 74/week @ 2024-10-07 145/week @ 2024-10-14 27/week @ 2024-10-21 7/week @ 2024-10-28

346 downloads per month

MIT license

59KB
1K SLoC

crates.io Documentation

Dependencies

spring-redis = { version = "<version>" }

Configuration items

[redis]
uri = "redis://127.0.0.1/" # redis database address

# The following are all optional configurations
connection_timeout = 10000  # Connection timeout, in milliseconds
response_timeout = 1000     # Response timeout, in milliseconds
number_of_retries = 6       # Retry times, interval time increases exponentially
exponent_base = 2           # Interval time exponential base, unit milliseconds
factor = 100                # Interval time growth factor, default 100 times growth
max_delay = 60000           # Maximum interval time

Component

After configuring the above configuration items, the plugin will automatically register a Redis connection management object. This object is an alias of redis::aio::ConnectionManager.

pub type Redis = redis::aio::ConnectionManager;

Extract the Component registered by the plugin

The RedisPlugin plugin automatically registers a connection management object for us. We can use Component to extract this connection pool from AppState. Component is an axum extractor.

async fn list_all_redis_key(Component(mut redis): Component<Redis>) -> Result<impl IntoResponse> {
    let keys: Vec<String> = redis.keys("*").await.context("redis request failed")?;
    Ok(Json(keys))
}

Complete code reference redis-example

Dependencies

~15–27MB
~385K SLoC