Redis client in Rust
The crate is called "redis-client".
``` rust extern crate redis_client;
use redisclient::commands::CommandSender; use redisclient::errors::RedisError;
fn setandget() -> Result
```
``` 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!(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(())
}
```
``` rust extern crate redis_client;
use redisclient::commands::{CommandBuilder, CommandSender, CommandSenderAsync}; use redisclient::errors::RedisError;
fn pipeline() -> Result
fn asyncpipeline() -> Result<(), RedisError> { let mut asyncclient = try!(redisclient::RedisClientAsync::new("localhost", "6379")); let cmd = &mut redisclient::RedisCommand::new(); cmd.set("key", "value2").get("key"); let results = try!(asyncclient.execredispipelinecommandasync(cmd, |results| { match results { Ok(values) => { for value in values { println!("{:?}", value.tostring()) } }, 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(())
}
```
Copyright (c) 2016 Gautier TANGUY
MIT License