Build Status Crates.io

redis-client

Redis client in Rust

Documentation

Getting started

The crate is called "redis-client".

API examples

set and get

``` rust extern crate redis_client;

use redisclient::commands::CommandSender; use redisclient::errors::RedisError;

fn setandget() -> Result { let mut client = try!(redisclient::RedisClient::new("localhost", "6379")); let setresult: String = try!(client.set("key", "value")); let getresult: String = try!(client.get("key")); Ok(getresult) }

```

Pipeline

``` rust extern crate redis_client;

use redisclient::commands::{CommandBuilder, CommandSender}; use redisclient::errors::RedisError;

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

```

Async get

``` rust extern crate redis_client;

use redisclient::commands::CommandSenderAsync; use redisclient::errors::RedisError;

fn asyncget() -> Result<(), RedisError> { let mut asyncclient = try!(redisclient::RedisClientAsync::new("localhost", "6379")); // the result argument in the closure is a Result try!(asyncclient.get("key", |result| { let resultvalue: String = match result { Ok(value) => value.into(), Err(err) => err.tostring(), }; 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(())

}

```

License

Copyright (c) 2016 Gautier TANGUY

MIT License