pub struct Pipeline { /* private fields */ }
Expand description
Pipeline
A pipeline is a way of queing up multiple queries, sending them to the server at once instead of sending them individually, avoiding round-trip-times while also simplifying usage in several places. Responses are returned in the order they are sent.
Example with the sync API
use skytable::{query, Pipeline, Element, RespCode};
use skytable::sync::Connection;
let mut con = Connection::new("127.0.0.1", 2003).unwrap();
let pipe = Pipeline::new()
.add(query!("set", "x", "100"))
.add(query!("heya", "echo me!"));
let ret = con.run_pipeline(pipe).unwrap();
assert_eq!(
ret,
vec![
Element::RespCode(RespCode::Okay),
Element::String("echo me!".to_owned())
]
);
Example with the async API
use skytable::{query, Pipeline, Element, RespCode};
use skytable::aio::Connection;
async fn run() {
let mut con = Connection::new("127.0.0.1", 2003).await.unwrap();
let pipe = Pipeline::new()
.add(query!("set", "x", "100"))
.add(query!("heya", "echo me!"));
let ret = con.run_pipeline(pipe).await.unwrap();
assert_eq!(
ret,
vec![
Element::RespCode(RespCode::Okay),
Element::String("echo me!".to_owned())
]
);
}
Implementations
This is supported on crate feature dbg
only.
This is supported on crate feature
dbg
only.Returns the query packet representation of this pipeline
Panics
This function will panic if the query is empty