#driver #valkey #async #sync

tokio-valkey

An ergonomic, asynchronous Valkey driver

2 releases

0.0.0-alpha2 Dec 4, 2024
0.0.0-alpha1 Nov 26, 2024

#492 in Hardware support

Download history 131/week @ 2024-11-25 143/week @ 2024-12-02

274 downloads per month
Used in bb8-valkey

MIT license

5KB
71 lines

valkey-rs

Crates.io docs

A Valkey driver for Rust.

This project will include sync, async, and pooling. It is still a work-in-progress.

Usage

Synchronous:

use std::net::{Ipv6Addr, SocketAddr};
use valkey::Client;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = SocketAddr::from((Ipv6Addr::LOCALHOST, 6379));
    let mut client = Client::connect(addr)?;

    client.set("hello", "world")?;

    let value = client.get("hello")?.unwrap();
    println!("Hello {value}");

    Ok(())
}

Async:

use std::net::{Ipv6Addr, SocketAddr};
use tokio_valkey::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = SocketAddr::from((Ipv6Addr::LOCALHOST, 6379));
    let mut client = Client::connect(addr).await?;

    client.set("hello", "world").await?;

    let value = client.get("hello").await?.unwrap();
    println!("Hello {value}");

    Ok(())
}

Crates

Use valkey for sync and tokio-valkey for async.

Dependencies

~2–10MB
~97K SLoC