Struct simple_redis::client::Client [−][src]
pub struct Client { /* fields omitted */ }
The redis client which enables to invoke redis operations.
Methods
impl Client
[src]
impl Client
pub fn is_connection_open(self: &Client) -> bool
[src]
pub 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.
pub fn quit(self: &mut Client) -> RedisEmptyResult
[src]
pub fn quit(self: &mut Client) -> RedisEmptyResult
Closes the internal connection to redis.
The client can still be reused and any invocation of other operations after this call,
will reopen the connection.
See redis QUIT command.
Example
match client.quit() { Err(error) => println!("Error: {}", error), _ => println!("Connection Closed.") }
pub fn run_command<T: FromRedisValue>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
[src]
pub fn run_command<T: FromRedisValue>(
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"), }
pub fn run_command_from_string_response<T: FromStr>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
[src]
pub fn run_command_from_string_response<T: FromStr>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
invokes the run_command and returns typed result
pub fn run_command_empty_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisEmptyResult
[src]
pub fn run_command_empty_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisEmptyResult
invokes the run_command but returns empty result
pub fn run_command_string_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisStringResult
[src]
pub fn run_command_string_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisStringResult
invokes the run_command but returns string result
pub fn run_command_bool_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisBoolResult
[src]
pub fn run_command_bool_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisBoolResult
invokes the run_command but returns bool result
pub fn subscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
[src]
pub 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");
pub fn psubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
[src]
pub 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*");
pub fn is_subscribed(self: &mut Client, channel: &str) -> bool
[src]
pub fn is_subscribed(self: &mut Client, channel: &str) -> bool
Returns true if subscribed to the provided channel.
pub fn is_psubscribed(self: &mut Client, channel: &str) -> bool
[src]
pub fn is_psubscribed(self: &mut Client, channel: &str) -> bool
Returns true if subscribed to the provided channel pattern.
pub fn unsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
[src]
pub fn unsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel.
pub fn punsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
[src]
pub fn punsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel pattern.
pub fn unsubscribe_all(self: &mut Client) -> RedisEmptyResult
[src]
pub fn unsubscribe_all(self: &mut Client) -> RedisEmptyResult
Unsubscribes from all channels.
pub fn get_message(self: &mut Client, timeout: u64) -> RedisMessageResult
[src]
pub 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), }
impl Client
[src]
impl Client
Defines the redis commands exposed by the redis client.
pub fn auth(&mut self, password: &str) -> RedisEmptyResult
[src]
pub 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") }
pub fn echo(&mut self, value: &str) -> RedisStringResult
[src]
pub fn echo(&mut self, value: &str) -> RedisStringResult
See redis ECHO command.
pub fn publish(&mut self, channel: &str, message: &str) -> RedisEmptyResult
[src]
pub 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") }
pub fn get<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
[src]
pub 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) }
pub fn get_string(self: &mut Client, key: &str) -> RedisStringResult
[src]
pub 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) }
pub fn set<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
[src]
pub 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") }
pub fn setex<T: RedisArg>(
&mut self,
key: &str,
value: T,
seconds: usize
) -> RedisEmptyResult
[src]
pub fn setex<T: RedisArg>(
&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") }
pub fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult
[src]
pub fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult
See redis SETNX command.
pub fn getset<T: RedisArg, V: FromStr>(
&mut self,
key: &str,
value: T
) -> RedisResult<V>
[src]
pub fn getset<T: RedisArg, V: FromStr>(
&mut self,
key: &str,
value: T
) -> RedisResult<V>
See redis GETSET command.
pub fn getset_string<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisStringResult
[src]
pub fn getset_string<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisStringResult
See redis GETSET command.
pub fn del(&mut self, key: &str) -> RedisEmptyResult
[src]
pub fn del(&mut self, key: &str) -> RedisEmptyResult
See redis DEL command.
pub fn exists(&mut self, key: &str) -> RedisBoolResult
[src]
pub fn exists(&mut self, key: &str) -> RedisBoolResult
See redis EXISTS command.
pub fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult
[src]
pub fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult
See redis EXPIRE command.
pub fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult
[src]
pub fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult
See redis PEXPIRE command.
pub fn persist(&mut self, key: &str) -> RedisEmptyResult
[src]
pub fn persist(&mut self, key: &str) -> RedisEmptyResult
See redis PERSIST command.
pub fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
[src]
pub fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAME command.
pub fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
[src]
pub fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAMENX command.
pub fn append(&mut self, key: &str, value: &str) -> RedisEmptyResult
[src]
pub fn append(&mut self, key: &str, value: &str) -> RedisEmptyResult
See redis APPEND command.
pub fn incr(&mut self, key: &str) -> RedisResult<i64>
[src]
pub fn incr(&mut self, key: &str) -> RedisResult<i64>
See redis INCR command.
pub fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64>
[src]
pub fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64>
See redis INCRBY command.
pub fn incrbyfloat<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisResult<f64>
[src]
pub fn incrbyfloat<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisResult<f64>
See redis INCRBYFLOAT command.
pub fn strlen(&mut self, key: &str) -> RedisResult<i32>
[src]
pub fn strlen(&mut self, key: &str) -> RedisResult<i32>
See redis STRLEN command.
pub fn keys(&mut self, pattern: &str) -> RedisResult<Vec<String>>
[src]
pub fn keys(&mut self, pattern: &str) -> RedisResult<Vec<String>>
See redis KEYS command.
pub fn hget<T: FromStr>(
self: &mut Client,
key: &str,
field: &str
) -> RedisResult<T>
[src]
pub fn hget<T: FromStr>(
self: &mut Client,
key: &str,
field: &str
) -> RedisResult<T>
See redis HGET command.
pub fn hget_string(
self: &mut Client,
key: &str,
field: &str
) -> RedisStringResult
[src]
pub fn hget_string(
self: &mut Client,
key: &str,
field: &str
) -> RedisStringResult
See redis HGET command.
pub fn hgetall(
self: &mut Client,
key: &str
) -> RedisResult<HashMap<String, String>>
[src]
pub 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), }
pub fn hset<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn hset<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
See redis HSET command.
pub fn hsetnx<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn hsetnx<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
See redis HSETNX command.
pub fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult
[src]
pub fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult
See redis HDEL command.
pub fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult
[src]
pub fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult
See redis HEXISTS command.
pub fn hkeys(&mut self, key: &str) -> RedisResult<Vec<String>>
[src]
pub fn hkeys(&mut self, key: &str) -> RedisResult<Vec<String>>
See redis HKEYS command.
pub fn hvals(&mut self, key: &str) -> RedisResult<Vec<String>>
[src]
pub fn hvals(&mut self, key: &str) -> RedisResult<Vec<String>>
See redis HVALS command.
pub fn lset<T: RedisArg>(
self: &mut Client,
key: &str,
index: isize,
value: T
) -> RedisEmptyResult
[src]
pub fn lset<T: RedisArg>(
self: &mut Client,
key: &str,
index: isize,
value: T
) -> RedisEmptyResult
See redis LSET command.
pub fn lindex<T: FromStr>(
self: &mut Client,
key: &str,
index: isize
) -> RedisResult<T>
[src]
pub fn lindex<T: FromStr>(
self: &mut Client,
key: &str,
index: isize
) -> RedisResult<T>
See redis HGET command.
pub fn lindex_string(
self: &mut Client,
key: &str,
index: isize
) -> RedisStringResult
[src]
pub fn lindex_string(
self: &mut Client,
key: &str,
index: isize
) -> RedisStringResult
See redis HGET command.
pub fn llen(self: &mut Client, key: &str) -> RedisResult<i32>
[src]
pub fn llen(self: &mut Client, key: &str) -> RedisResult<i32>
See redis LLEN command.
pub fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
[src]
pub fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis LPOP command.
pub fn lpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn lpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis LPUSH command.
pub fn lpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn lpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis LPUSHX command.
pub fn lrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisResult<Vec<String>>
[src]
pub fn lrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisResult<Vec<String>>
See redis LRANGE command.
pub fn lrem<T: RedisArg>(
self: &mut Client,
key: &str,
count: isize,
value: T
) -> RedisEmptyResult
[src]
pub fn lrem<T: RedisArg>(
self: &mut Client,
key: &str,
count: isize,
value: T
) -> RedisEmptyResult
See redis LREM command.
pub fn ltrim(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisEmptyResult
[src]
pub fn ltrim(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisEmptyResult
See redis LTRIM command.
pub fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
[src]
pub fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis RPOP command.
pub fn rpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn rpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis RPUSH command.
pub fn rpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
[src]
pub fn rpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
See redis RPUSHX command.
pub fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32>
[src]
pub fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32>
See redis SADD command.
pub fn scard(self: &mut Client, key: &str) -> RedisResult<i32>
[src]
pub fn scard(self: &mut Client, key: &str) -> RedisResult<i32>
See redis SCARD command.
pub fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>>
[src]
pub fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>>
See redis SDIFF command.
pub fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult
[src]
pub fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult
See redis SISMEMBER command.
pub fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>>
[src]
pub fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>>
See redis SMEMBERS command.
pub fn smove(
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str
) -> RedisEmptyResult
[src]
pub fn smove(
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str
) -> RedisEmptyResult
See redis SMOVE command.
pub fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult
[src]
pub fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult
See redis SREM command.