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§

authenticators
cluster
compression
consistency
The module contains Rust representation of Cassandra consistency levels.
envelope_parser
error
frame
frame_encoding
future
load_balancing
query
retry
speculative_execution
Pre-emptively query another node if the current one takes too long to respond.
statement
transport
This module contains a declaration of CdrsTransport trait which should be implemented for particular transport to be able using it as transport of CDRS client.
types

Macros§

query_values
Transforms arguments to values consumed by queries.

Type Aliases§

Error
Result