Crates.io | spring-redis |
lib.rs | spring-redis |
version | 0.3.0 |
source | src |
created_at | 2024-08-07 04:45:08.376397 |
updated_at | 2024-12-01 03:17:57.337126 |
description | Integrate redis-rs with spring-rs |
homepage | |
repository | https://github.com/spring-rs/spring-rs |
max_upload_size | |
id | 1328068 |
size | 9,957 |
spring-redis = { version = "<version>" }
[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
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;
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