5 个版本 (破坏性更新)

0.5.0 2020年6月2日
0.4.0 2020年4月23日
0.3.0 2020年4月23日
0.2.0 2020年3月24日
0.1.0 2020年2月18日

#2220数据库接口

每月40次下载
用于 2 crates

MIT 许可证

49KB
828

githubactions Latest Version documentation

redisgraph-rs

redisgraph-rs 是RedisGraph,Redis的图数据库的惯用Rust客户端。

该crate解析RedisGraph的响应并将其转换为普通的Rust值。它提供了一个非常灵活的API,允许您仅使用一个函数: Graph::query,来检索单个值、单个记录或多个记录。

如果您想使用这个crate,请将以下内容添加到您的Cargo.toml中

[dependencies]
redis = "0.15.1"
redisgraph = "0.1.0"

警告:这个库还没有经过彻底测试,一些功能仍然缺失。请期待bug和破坏性变更。

资源

示例

首先,使用以下命令在您的机器上运行RedisGraph

$ docker run --name redisgraph-test -d --rm -p 6379:6379 redislabs/redisgraph

然后,尝试以下代码

use redis::Client;
use redisgraph::{Graph, RedisGraphResult};

fn main() -> RedisGraphResult<()> {
    let client = Client::open("redis://127.0.0.1")?;
    let mut connection = client.get_connection()?;

    let mut graph = Graph::open(connection, "MotoGP".to_string())?;

    // Create six nodes (three riders, three teams) and three relationships between them.
    graph.mutate("CREATE (:Rider {name: 'Valentino Rossi', birth_year: 1979})-[:rides]->(:Team {name: 'Yamaha'}), \
        (:Rider {name:'Dani Pedrosa', birth_year: 1985, height: 1.58})-[:rides]->(:Team {name: 'Honda'}), \
        (:Rider {name:'Andrea Dovizioso', birth_year: 1986, height: 1.67})-[:rides]->(:Team {name: 'Ducati'})")?;

    // Get the names and birth years of all riders in team Yamaha.
    let results: Vec<(String, u32)> = graph.query("MATCH (r:Rider)-[:rides]->(t:Team) WHERE t.name = 'Yamaha' RETURN r.name, r.birth_year")?;
    // Since we know just one rider in our graph rides for team Yamaha,
    // we can also write this and only get the first record:
    let (name, birth_year): (String, u32) = graph.query("MATCH (r:Rider)-[:rides]->(t:Team) WHERE t.name = 'Yamaha' RETURN r.name, r.birth_year")?;
    // Let's now get all the data about the riders we have.
    // Be aware of that we only know the height of some riders, and therefore we use an `Option`:
    let results: Vec<(String, u32, Option<f32>)> = graph.query("MATCH (r:Rider) RETURN r.name, r.birth_year, r.height")?;

    // That was just a demo; we don't need this graph anymore. Let's delete it from the database:
    graph.delete()?;

    Ok(())
}

依赖项

~3.5–4.5MB
~114K SLoC