Crate redisgraphio

Source
Expand description

§redisgraphio

crates.io

This is a rust client library for working with the RedisGraph module for Redis.
It works in conjunction with redis-rs by implementing a trait for the redis connection.

§Features

§Synchronous usage

[dependencies]
redis = "0.21" # or higher
redisgraphio = "0.1"
use redis::RedisResult;
use redisgraphio::*;

fn rider_example() -> RedisResult<()> {
    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_connection()?;
    con.graph_query_void("my_graph", query!(
        "CREATE (:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'})"
    ))?;
    // Assuming this could be malicious user input you need to escape
    let team_name = "Yamaha";
    let riders: Vec<(Node,)> = con.graph_query(
        "my_graph", // graph to query
        query!(
            "MATCH (rider:Rider)-[:rides]->(:Team {name: $team}) RETURN rider",
            {
                "team" => team_name
            },
            true // Optinal parameter to enable read only access, default is false
    )
    )?.data;
    for (rider,) in riders {
        let name: String = rider.get_property_by_index(0)?;
        println!("{name}")
    }
    Ok(())
}

§Asynchronous usage

To enable the redisgraphio async commands either enable the tokio-comp or async-std-comp

[dependencies]
redis = "0.21.0"
redis-graph = { version = "0.1", features = ['tokio-comp'] }
use redis::RedisResult;
use redisgraphio::*;

async fn rider_example() -> RedisResult<()> {
    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_async_connection().await?;
    con.graph_query_void("my_graph", query!(
        "CREATE (:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'})"
    )).await?;
    // Assuming this could be malicious user input you need to escape
    let team_name = "Yamaha";
    let riders: Vec<(Node,)> = con.graph_query(
        "my_graph",
        query!(
            "MATCH (rider:Rider)-[:rides]->(:Team {name: $team}) RETURN rider",
            {
                "team" => team_name
            },
            true // Optinal parameter to enable read only access, default is false
    )
    ).await?.data;
    for (rider,) in riders {
        let name: String = rider.get_property_by_index(0)?;
        println!("{name}")
    }
    Ok(())
}

§Credit

The crates API was inspired by the redis-graph crate which also implents traits on the redis connection.
The serialisation was inspired by redis-rs itself.

Macros§

query
Macro for creating a GraphQuery

Structs§

GeoPoint
The type returned by the point method in cypher
GraphMap
Map typed as returned by RETURN {a: 1}
GraphPath
Type for graph paths as returned by MATCH p=(:A)-[:B]->(:C) RETURN p
GraphQuery
Contains information for constructing the query. Primarily generated by the [query] macro
GraphResponse
Overview
Node
Node Type
Relationship
Relationship Type

Enums§

GraphStatistic
Execution statistics
GraphValue
An enum containing every possible type that can be returned by redisgraph
Parameter
Used for inserting user data in the query and escaping it properly This type gets primarilly constructed by the query! macro but can also be constructed with Parameter::from

Traits§

FromGraphValue
Trait for converting the response to an arbitray type which implents the trait This is similar to the FromRedisValue trait from redis
GraphCommands
Implements redis graph related commands for an synchronous connection
PropertyAccess
Trait for unifying access to Node and Relationship properties

Functions§

create_rediserror
Helper for creating a Rediserror
from_graph_value
Shorthand for FromGraphValue::from_graph_value(value)