Crate cdrs_tokio
source ·Expand description
cdrs is a native Cassandra DB client written in Rust.
§Getting started
This example configures a cluster consisting of a single node, and uses round-robin load balancing.
use cdrs_tokio::cluster::session::{TcpSessionBuilder, SessionBuilder};
use cdrs_tokio::cluster::NodeTcpConfigBuilder;
use cdrs_tokio::load_balancing::RoundRobinLoadBalancingStrategy;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let cluster_config = NodeTcpConfigBuilder::new()
.with_contact_point("127.0.0.1:9042".into())
.build()
.await
.unwrap();
let session = TcpSessionBuilder::new(RoundRobinLoadBalancingStrategy::new(), cluster_config)
.build()
.await
.unwrap();
let create_ks = "CREATE KEYSPACE IF NOT EXISTS test_ks WITH REPLICATION = { \
'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
session
.query(create_ks)
.await
.expect("Keyspace create error");
}
§Nodes and load balancing
In order to maximize efficiency, the driver needs to be appropriately configured for given use
case. Please look at available load balancers and
node distance evaluators to pick the optimal
solution when building the Session
. Topology-aware load
balancing is preferred when dealing with multi-node clusters, otherwise simpler strategies might
prove more efficient.
Modules§
- The module contains Rust representation of Cassandra consistency levels.
- Pre-emptively query another node if the current one takes too long to respond.
- This module contains a declaration of
CdrsTransport
trait which should be implemented for particular transport in order to be able using it as a transport of CDRS client.
Macros§
- Transforms arguments to values consumed by queries.