7 unstable releases (3 breaking)

Uses old Rust 2015

0.5.0 Feb 21, 2016
0.4.3 Feb 7, 2016
0.4.1 Jan 28, 2016
0.3.0 Jan 24, 2016
0.1.1 Jan 21, 2016

#1015 in Database interfaces

Download history 20/week @ 2023-12-04 6/week @ 2023-12-11 5/week @ 2023-12-18 37/week @ 2023-12-25 42/week @ 2024-01-01 2/week @ 2024-01-08 65/week @ 2024-02-26 9/week @ 2024-03-04

74 downloads per month

MIT license

125KB
2.5K SLoC

Build Status Crates.io

redis-client

Redis client in Rust

Documentation

Getting started

The crate is called "redis-client".

API examples

set and get

extern crate redis_client;

use redis_client::commands::CommandSender;
use redis_client::errors::RedisError;

fn set_and_get() -> Result<String, RedisError> {
    let mut client = try!(redis_client::RedisClient::new("localhost", "6379"));
    let set_result: String = try!(client.set("key", "value"));
    let get_result: String = try!(client.get("key"));
    Ok(get_result)
}

Async get

extern crate redis_client;

use redis_client::commands::CommandSenderAsync;
use redis_client::errors::RedisError;

fn async_get() -> Result<(), RedisError> {
    let mut async_client = try!(redis_client::RedisClientAsync::new("localhost", "6379"));
    // the result argument in the closure is a Result<RedisResult, RedisError>
    try!(async_client.get("key", |result| {
        let result_value: String  = match result {
            Ok(value) => value.into(),
            Err(err) => err.to_string(),
        };
        println!("{:?}", result_value);
    }));

     try!(async_client.get("key2", |result| {
        let result_value: String  = match result {
            Ok(value) => value.into(),
            Err(err) => err.to_string(),
        };
        println!("{:?}", result_value);
    }));

    loop {

        sleep(Duration::new(0, 1000 * 1000 * 1000));

        // this method will call callbacks when their command executions are over.
        async_client.pump();
    }

    Ok(())
}

Pipeline

extern crate redis_client;

use redis_client::commands::{CommandBuilder, CommandSender, CommandSenderAsync};
use redis_client::errors::RedisError;

fn pipeline() -> Result<Vec<RedisResult>, RedisError> {
    let mut client = try!(redis_client::RedisClient::new("localhost", "6379"));
    let cmd = &mut redis_client::RedisCommand::new();
    cmd.set("key", "value2").get("key");
    let results = try!(client.exec_redis_pipeline_command(cmd));
    Ok(results)
}

fn async_pipeline() -> Result<(), RedisError> {
    let mut async_client = try!(redis_client::RedisClientAsync::new("localhost", "6379"));
    let cmd = &mut redis_client::RedisCommand::new();
    cmd.set("key", "value2").get("key");
    try!(async_client.exec_redis_pipeline_command_async(cmd, |results| {
        match results {
            Ok(values) => {
                for value in values {
                    println!("{:?}", value.convert::<String>())
                }
            },
            Err(err) => println!("{:?}", err.to_string()),
        };
    }));

    loop {

        sleep(Duration::new(0, 1000 * 1000 * 1000));

        // this method will call callbacks when their command executions are over.
        async_client.pump();
    }
    Ok(())
}

License

Copyright (c) 2016 Gautier TANGUY

MIT License

Dependencies

~325–550KB