7 releases (breaking)

0.9.0 Jun 11, 2023
0.8.0 Mar 23, 2023
0.6.0 Mar 20, 2023
0.5.0 Mar 19, 2023
0.2.0 Sep 12, 2022
Download history 21/week @ 2023-06-02 34/week @ 2023-06-09 41/week @ 2023-06-16 28/week @ 2023-06-23 51/week @ 2023-06-30 47/week @ 2023-07-07 27/week @ 2023-07-14 31/week @ 2023-07-21 13/week @ 2023-07-28 27/week @ 2023-08-04 16/week @ 2023-08-11 24/week @ 2023-08-18 15/week @ 2023-08-25 20/week @ 2023-09-01 27/week @ 2023-09-08 18/week @ 2023-09-15

84 downloads per month
Used in 4 crates (via redis-swapplex)

MIT license



License Cargo Documentation

Redis multiplexing with reconnection notifications and MGET auto-batching

Why use this instead of redis::aio::ConnectionManager?

  • Error-free reconnection behavior: when a command would otherwise fail as a consequence of the connection being dropped, this library will immediately reconnect and retry when able without producing an otherwise avoidable IoError and with subsequent reconnections debounced 1500ms
  • ENV configuration simplifies kubernetes usage
  • Reconnects can be observed allowing for Redis server-assisted client-side caching using client tracking redirection
  • Integrated MGET auto-batching (up to 180x more performant than GET)

ENV Configuration

Composible connection urls are provided by environment variables using env-url with the REDIS prefix:



use redis::{AsyncCommands, RedisResult};
use redis_swapplex::get_connection;

async fn get_value(key: &str) -> RedisResult<String> {
  let mut conn = get_connection();

Runtime Configuration (optional)

For best performance, use the Tokio runtime as configured via the tokio::main or tokio::test macro with the crate attribute set to async_local while the barrier-protected-runtime feature is enabled on async-local. Doing so configures the Tokio runtime with a barrier that rendezvous runtime worker threads during shutdown in a way that ensures tasks never outlive thread local data owned by runtime worker threads and obviates the need for Box::leak as a means of lifetime extension.

Stable Usage

This crate conditionally makes use of type_alias_impl_trait and impl_trait_in_assoc_type to allow async fns in traits to be unboxed. To compile on stable the boxed feature flag can be used to downgrade async_t::async_trait to async_trait::async_trait.


~19K SLoC