Struct simple_redis::client::Client
[−]
[src]
pub struct Client { /* fields omitted */ }
The redis client which enables to invoke redis operations.
Methods
impl Client
[src]
Defines the redis commands exposed by the redis client.
fn auth(&mut self, password: &str) -> RedisEmptyResult
See redis AUTH command.
Example
match client.auth("my_password") { Err(error) => println!("Auth error: {}", error), _ => println!("Authenticated") }
fn echo(&mut self, value: &str) -> RedisStringResult
See redis ECHO command.
fn publish(&mut self, channel: &str, message: &str) -> RedisEmptyResult
See redis PUBLISH command.
Example
match client.publish("important_notifications", "message text") { Err(error) => println!("Publish error: {}", error), _ => println!("Message published") }
fn get<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis GET command.
Example
match client.get::<i64>("my_key") { Ok(value) => println!("Read value from Redis: {}", value), Err(error) => println!("Unable to get value from Redis: {}", error) }
fn get_string(self: &mut Client, key: &str) -> RedisStringResult
See redis GET command.
This function will always return a String response.
Example
match client.get_string("my_key") { Ok(value) => println!("Read value from Redis: {}", value), Err(error) => println!("Unable to get value from Redis: {}", error) }
fn set<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult
See redis SET command.
Example
match client.set("my_key", "my_value") { Err(error) => println!("Unable to set value in Redis: {}", error), _ => println!("Value set in Redis") }
fn setex<T: RedisArg>(
&mut self,
key: &str,
value: T,
seconds: usize
) -> RedisEmptyResult
&mut self,
key: &str,
value: T,
seconds: usize
) -> RedisEmptyResult
See redis SETEX command.
Example
match client.setex("my_key", "my_value", 10) { Err(error) => println!("Unable to set value in Redis: {}", error), _ => println!("Value set in Redis and will expire in 10 seconds") }
fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult
See redis SETNX command.
fn getset<T: RedisArg, V: FromStr>(
&mut self,
key: &str,
value: T
) -> RedisResult<V>
&mut self,
key: &str,
value: T
) -> RedisResult<V>
See redis GETSET command.
fn getset_string<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisStringResult
&mut self,
key: &str,
value: T
) -> RedisStringResult
See redis GETSET command.
fn del(&mut self, key: &str) -> RedisEmptyResult
See redis DEL command.
fn exists(&mut self, key: &str) -> RedisBoolResult
See redis EXISTS command.
fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult
See redis EXPIRE command.
fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult
See redis PEXPIRE command.
fn persist(&mut self, key: &str) -> RedisEmptyResult
See redis PERSIST command.
fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAME command.
fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAMENX command.
fn append(&mut self, key: &str, value: &str) -> RedisEmptyResult
See redis APPEND command.
fn incr(&mut self, key: &str) -> RedisResult<i64>
See redis INCR command.
fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64>
See redis INCRBY command.
fn incrbyfloat<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<f64>
See redis INCRBYFLOAT command.
fn strlen(&mut self, key: &str) -> RedisResult<i32>
See redis STRLEN command.
fn keys(&mut self, pattern: &str) -> RedisResult<Vec<String>>
See redis KEYS command.
fn hget<T: FromStr>(self: &mut Client, key: &str, field: &str) -> RedisResult<T>
See redis HGET command.
fn hget_string(self: &mut Client, key: &str, field: &str) -> RedisStringResult
See redis HGET command.
fn hgetall(self: &mut Client, key: &str) -> RedisResult<HashMap<String, String>>
See redis HGETALL command.
Example
match client.hgetall("my_map") { Ok(map) => { match map.get("my_field") { Some(value) => println!("Got field value from map: {}", value), None => println!("Map field is emtpy"), } }, Err(error) => println!("Unable to read map from Redis: {}", error), }
fn hset<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
See redis HSET command.
fn hsetnx<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
See redis HSETNX command.
fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult
See redis HDEL command.
fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult
See redis HEXISTS command.
fn hkeys(&mut self, key: &str) -> RedisResult<Vec<String>>
See redis HKEYS command.
fn hvals(&mut self, key: &str) -> RedisResult<Vec<String>>
See redis HVALS command.
fn lset<T: RedisArg>(
self: &mut Client,
key: &str,
index: isize,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
index: isize,
value: T
) -> RedisEmptyResult
See redis LSET command.
fn lindex<T: FromStr>(
self: &mut Client,
key: &str,
index: isize
) -> RedisResult<T>
self: &mut Client,
key: &str,
index: isize
) -> RedisResult<T>
See redis HGET command.
fn lindex_string(
self: &mut Client,
key: &str,
index: isize
) -> RedisStringResult
self: &mut Client,
key: &str,
index: isize
) -> RedisStringResult
See redis HGET command.
fn llen(self: &mut Client, key: &str) -> RedisResult<i32>
See redis LLEN command.
fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis LPOP command.
fn lpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis LPUSH command.
fn lpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis LPUSHX command.
fn lrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisResult<Vec<String>>
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisResult<Vec<String>>
See redis LRANGE command.
fn lrem<T: RedisArg>(
self: &mut Client,
key: &str,
count: isize,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
count: isize,
value: T
) -> RedisEmptyResult
See redis LREM command.
fn ltrim(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisEmptyResult
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisEmptyResult
See redis LTRIM command.
fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis RPOP command.
fn rpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis RPUSH command.
fn rpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis RPUSHX command.
fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32>
See redis SADD command.
fn scard(self: &mut Client, key: &str) -> RedisResult<i32>
See redis SCARD command.
fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>>
See redis SDIFF command.
fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult
See redis SISMEMBER command.
fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>>
See redis SMEMBERS command.
fn smove(
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str
) -> RedisEmptyResult
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str
) -> RedisEmptyResult
See redis SMOVE command.
fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult
See redis SREM command.
impl Client
[src]
fn is_connection_open(self: &Client) -> bool
Returns true if the currently stored connection is valid, otherwise false.
There is no need to call this function as any redis operation invocation will
ensure a valid connection is created.
fn run_command<T: FromRedisValue>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
Invokes the requested command with the provided arguments (all provided via args) and returns the operation
response.
This function ensures that we have a valid connection and it is used internally by all other exposed
commands.
This function is also public to enable invoking operations that are not directly exposed by the client.
Arguments
command
- The Redis command, for example:GET
args
- Vector of arguments for the given command
Example
match client.run_command::<String>("ECHO", vec!["testing"]) { Ok(value) => assert_eq!(value, "testing"), _ => panic!("test error"), }
fn run_command_from_string_response<T: FromStr>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
invokes the run_command and returns typed result
fn run_command_empty_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisEmptyResult
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisEmptyResult
invokes the run_command but returns empty result
fn run_command_string_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisStringResult
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisStringResult
invokes the run_command but returns string result
fn run_command_bool_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisBoolResult
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisBoolResult
invokes the run_command but returns bool result
fn subscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Subscribes to the provided channel.
Actual subscription only occurs at the first call to get_message.
Arguments
channel
- The channel name, for example:level_info
Example
client.subscribe("important_notifications");
fn psubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Subscribes to the provided channel pattern.
Actual subscription only occurs at the first call to get_message.
Arguments
channel
- The channel pattern, for example:level_*
Example
client.psubscribe("important_notifications*");
fn unsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel.
fn punsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel pattern.
fn get_message(self: &mut Client, timeout: u64) -> RedisMessageResult
Fetches the next message from any of the subscribed channels.
This function will return a TimeoutError in case no message was read in the provided timeout value (defined in
millies).
If the provided timeout value is 0, there will be no timeout and the call will block until a message is read or
a connection error happens.
Arguments
timeout
- The timeout value in millies or 0 for no timeout
Example
client.subscribe("important_notifications"); // get next message (wait up to 5 seconds, 0 for no timeout) match client.get_message(5000) { Ok(message) => { let payload : String = message.get_payload().unwrap(); println!("Got message: {}", payload); }, Err(error) => println!("Error while fetching message, should retry again, info: {}", error), }