7 unstable releases (3 breaking)

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

#361 in Database interfaces

Download history 18/week @ 2019-11-27 9/week @ 2019-12-04 272/week @ 2019-12-11 9/week @ 2019-12-25 9/week @ 2020-01-08 28/week @ 2020-01-15 1/week @ 2020-02-05 12/week @ 2020-02-12 20/week @ 2020-02-19 18/week @ 2020-02-26 18/week @ 2020-03-04 9/week @ 2020-03-11

133 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

~380KB