Crate redis_swapplex

Source
Expand description

Redis multiplexing with reconnection notifications and MGET auto-batching. Connection configuration is provided by env-url.

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)

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

REDIS_URL=redis://127.0.0.1:6379
# Override env mapping for easy kubernetes config
REDIS_HOST_ENV=MONOLITH_STAGE_REDIS_MASTER_PORT_6379_TCP_ADDR
REDIS_PORT_ENV=MONOLITH_STAGE_REDIS_MASTER_SERVICE_PORT_REDIS
use redis::{AsyncCommands, RedisResult};
use redis_swapplex::get_connection;

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

Structs§

Traits§

Functions§

  • A stream notifying whenever the current or a new connection is connected; useful for client tracking redirection
  • Get the value of a key using auto-batched MGET commands
  • Get a managed multiplexed connection for the default env-configured Redis database
  • Notify the next time a connection is established
  • Set the value of a key using auto-batched MSET commands

Derive Macros§