Crate redis_cluster_async
source ·Expand description
This library extends redis-rs library to be able to use Redis Cluster asynchronously.
Client
implements the redis::ConnectionLike
and redis::Commands
traits,
so you can use redis-rs’s access methods.
If you want more information, read the redis-rs documentation.
Note that this library currently does not have Pubsub features.
Example
use redis_cluster_async::{Client, redis::{Commands, cmd}};
#[tokio::main]
async fn main() -> redis::RedisResult<()> {
let nodes = vec!["redis://127.0.0.1:7000/", "redis://127.0.0.1:7001/", "redis://127.0.0.1:7002/"];
let client = Client::open(nodes)?;
let mut connection = client.get_connection().await?;
cmd("SET").arg("test").arg("test_data").query_async(&mut connection).await?;
let res: String = cmd("GET").arg("test").query_async(&mut connection).await?;
assert_eq!(res, "test_data");
Ok(())
}
Pipelining
use redis_cluster_async::{Client, redis::pipe};
#[tokio::main]
async fn main() -> redis::RedisResult<()> {
let nodes = vec!["redis://127.0.0.1:7000/", "redis://127.0.0.1:7001/", "redis://127.0.0.1:7002/"];
let client = Client::open(nodes)?;
let mut connection = client.get_connection().await?;
let key = "test2";
let mut pipe = pipe();
pipe.rpush(key, "123").ignore()
.ltrim(key, -10, -1).ignore()
.expire(key, 60).ignore();
pipe.query_async(&mut connection)
.await?;
Ok(())
}
Re-exports
pub use redis;
Structs
- This is a Redis cluster client.
- This is a connection of Redis cluster.