2个版本

0.1.1 2020年6月24日
0.1.0 2020年6月24日

#2156 in 数据库接口

Download history 190/week @ 2024-03-13 139/week @ 2024-03-20 157/week @ 2024-03-27 143/week @ 2024-04-03 72/week @ 2024-04-10 195/week @ 2024-04-17 270/week @ 2024-04-24 170/week @ 2024-05-01 101/week @ 2024-05-08 107/week @ 2024-05-15 12/week @ 2024-05-22 69/week @ 2024-05-29 214/week @ 2024-06-05 112/week @ 2024-06-12 38/week @ 2024-06-19 5/week @ 2024-06-26

每月 397次下载

MIT/Apache

78KB
2K SLoC

Apache Ignite 薄客户端

使用

[dependencies]
ignite-rs = "0.1.0"
fn main() {
    // Create a client configuration
    let mut client_config = ClientConfig::new("localhost:10800");

    // Optionally define user, password, TCP configuration
    // client_config.username = Some("ignite".into());
    // client_config.password = Some("ignite".into());

    // Create an actual client. The protocol handshake is done here
    let mut ignite = ignite_rs::new_client(client_config).unwrap();

    // Get a list of present caches
    if let Ok(names) = ignite.get_cache_names() {
        println!("ALL caches: {:?}", names)
    }

    // Create a typed cache named "test"
    let hello_cache: Cache<MyType, MyOtherType> = ignite
        .get_or_create_cache::<MyType, MyOtherType>("test")
        .unwrap();

    let key = MyType {
        bar: "AAAAA".into(),
        foo: 999,
    };
    let val = MyOtherType {
        list: vec![Some(FooBar {})],
        arr: vec![-23423423i64, -2342343242315i64],
    };

    // Put value
    hello_cache.put(&key, &val).unwrap();

    // Retrieve value
    println!("{:?}", hello_cache.get(&key).unwrap());
}

// Define your structs, that could be used as keys or values
#[derive(IgniteObj, Clone, Debug)]
struct MyType {
    bar: String,
    foo: i32,
}

#[derive(IgniteObj, Clone, Debug)]
struct MyOtherType {
    list: Vec<Option<FooBar>>,
    arr: Vec<i64>,
}

#[derive(IgniteObj, Clone, Debug)]
struct FooBar {}

类型映射

以下是支持的Rust类型及其对应的Ignite类型和类型代码 (https://apacheignite.readme.io/docs/binary-client-protocol-data-format)

Rust类型 Ignite类型 Ignite类型代码
u8 字节 1
u16 字符 7
i16 短整型 2
i32 整型 3
i64 长整型 4
f32 浮点型 5
f64 双精度浮点型 6
bool 布尔型 8
ignite_rs::Enum 枚举 28
字符串 字符串 9
Vec<u8> 字节数组 12
Vec<u16> 字符数组 18
Vec<i16> 短整型数组 13
Vec<i32> 整型数组 14
Vec<i64> 长整型数组 15
Vec<f32> 浮点型数组 16
Vec<f64> 双精度浮点型数组 17
Vec<bool> 布尔型数组 19
Vec<Option<T>> where T: WritableType + ReadableType Ser => ArrObj; Deser => ArrObj or Collection Ser => 23; Deser => 23 or 24
Option<T> where T: WritableType + ReadableType None => Null; Some => inner type None => 101
用户定义的结构体 ComplexObj 103

用户定义的类型

您可以将其自己的类型用作键/值。您需要做的是在您的结构体中添加一个 #[derive(IgniteObj)] 属性。

[dependencies]
ignite-rs_derive = "0.1.0"
#[derive(IgniteObj)]
struct MyOtherType {
    list: Vec<Option<FooBar>>,
    arr: Vec<i64>,
}

WriteableTypeReadableType 实现将为您生成类型。请注意,您的结构体中的所有字段也应当实现 WriteableTypeReadableType

SSL/TLS

通过 rustls 支持加密连接。

[dependencies.ignite-rs]
version = "0.1.0"
features = ["ssl"]
fn main() {

    // Create ssl config
    let ssl_conf: rustls::ClientConfig = ...;
    // Define hostname which certificate should be verified against
    let hostname = String::from("mydomain.com");

    // Create a client configuration
    let mut client_config = ClientConfig::new("localhost:10800", ssl_conf, hostname);
    
    ...
}

依赖

~0–2.8MB
~63K SLoC