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) -> Result<(), RedisError>
See redis AUTH command.
Examples
match client.auth("my_password") { Err(error) => println!("Auth error: {}", error), _ => println!("Authenticated") }
fn echo(&mut self, value: &str) -> Result<String, RedisError>
See redis ECHO command.
fn publish(&mut self, channel: &str, message: &str) -> Result<(), RedisError>
See redis PUBLISH command.
Examples
match client.publish("important_notifications", "message text") { Err(error) => println!("Publish error: {}", error), _ => println!("Message published") }
fn get(self: &mut Client, key: &str) -> Result<String, RedisError>
See redis GET command.
Examples
match client.get("my_key") { Ok(value) => println!("Read value from Redis: {}", value), Err(error) => println!("Unable to get value from Redis: {}", error) }
fn set(self: &mut Client, key: &str, value: &str) -> Result<(), RedisError>
See redis SET command.
Examples
match client.set("my_key", "my_value") { Err(error) => println!("Unable to set value in Redis: {}", error), _ => println!("Value set in Redis") }
fn setex(
&mut self,
key: &str,
value: &str,
seconds: usize
) -> Result<(), RedisError>
&mut self,
key: &str,
value: &str,
seconds: usize
) -> Result<(), RedisError>
See redis SETEX command.
Examples
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(&mut self, key: &str, value: &str) -> Result<(), RedisError>
See redis SETNX command.
fn getset(&mut self, key: &str, value: &str) -> Result<String, RedisError>
See redis GETSET command.
fn del(&mut self, key: &str) -> Result<(), RedisError>
See redis DEL command.
fn exists(&mut self, key: &str) -> Result<bool, RedisError>
See redis EXISTS command.
fn expire(&mut self, key: &str, seconds: usize) -> Result<(), RedisError>
See redis EXPIRE command.
fn persist(&mut self, key: &str) -> Result<(), RedisError>
See redis PERSIST command.
fn rename(&mut self, key: &str, new_key: &str) -> Result<(), RedisError>
See redis RENAME command.
fn renamenx(&mut self, key: &str, new_key: &str) -> Result<(), RedisError>
See redis RENAMENX command.
fn append(&mut self, key: &str, value: &str) -> Result<(), RedisError>
See redis APPEND command.
fn incr(&mut self, key: &str) -> Result<i64, RedisError>
See redis INCR command.
fn incrby(&mut self, key: &str, value: i64) -> Result<i64, RedisError>
See redis INCRBY command.
fn incrbyfloat(&mut self, key: &str, value: f64) -> Result<f64, RedisError>
See redis INCRBYFLOAT command.
fn strlen(&mut self, key: &str) -> Result<i32, RedisError>
See redis STRLEN 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>
) -> Result<T, RedisError>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<T, RedisError>
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.
Examples
match client.run_command::<String>("ECHO", vec!["testing"]) { Ok(value) => assert_eq!(value, "testing"), _ => panic!("test error"), }
fn run_command_empty_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<(), RedisError>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<(), RedisError>
invokes the run_command but returns empty result
fn run_command_string_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<String, RedisError>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<String, RedisError>
invokes the run_command but returns string result
fn run_command_bool_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<bool, RedisError>
self: &mut Client,
command: &str,
args: Vec<&str>
) -> Result<bool, RedisError>
invokes the run_command but returns bool result
fn subscribe(self: &mut Client, channel: &str) -> Result<(), RedisError>
Subscribes to the provided channel.
Actual subscription only occurs at the first call to get_message.
Examples
client.subscribe("important_notifications");
fn psubscribe(self: &mut Client, channel: &str) -> Result<(), RedisError>
Subscribes to the provided channel pattern.
Actual subscription only occurs at the first call to get_message.
Examples
client.psubscribe("important_notifications*");
fn unsubscribe(self: &mut Client, channel: &str) -> Result<(), RedisError>
Unsubscribes from the provided channel.
fn punsubscribe(self: &mut Client, channel: &str) -> Result<(), RedisError>
Unsubscribes from the provided channel pattern.
fn get_message(self: &mut Client) -> Result<Msg, RedisError>
Fetches the next message from any of the subscribed channels.
Examples
client.subscribe("important_notifications"); match client.get_message() { Ok(message) => { let payload : String = message.get_payload().unwrap(); println!("Got message: {}", payload); }, Err(error) => println!("Error while fetching message, should retry again.") }