Struct simple_redis::client::Client
source · pub struct Client { /* private fields */ }
Expand description
The redis client which enables to invoke redis operations.
Implementations§
source§impl Client
impl Client
sourcepub fn is_connection_open(self: &mut Client) -> bool
pub fn is_connection_open(self: &mut 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.
sourcepub fn quit(self: &mut Client) -> RedisEmptyResult
pub fn quit(self: &mut Client) -> RedisEmptyResult
sourcepub fn run_command<T: FromRedisValue>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
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"),
}
sourcepub fn run_command_from_string_response<T: FromStr>(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisResult<T>
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
sourcepub fn run_command_empty_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisEmptyResult
pub fn run_command_empty_response( self: &mut Client, command: &str, args: Vec<&str> ) -> RedisEmptyResult
invokes the run_command but returns empty result
sourcepub fn run_command_string_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisStringResult
pub fn run_command_string_response( self: &mut Client, command: &str, args: Vec<&str> ) -> RedisStringResult
invokes the run_command but returns string result
sourcepub fn run_command_bool_response(
self: &mut Client,
command: &str,
args: Vec<&str>
) -> RedisBoolResult
pub fn run_command_bool_response( self: &mut Client, command: &str, args: Vec<&str> ) -> RedisBoolResult
invokes the run_command but returns bool result
sourcepub fn subscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
pub fn subscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
sourcepub fn psubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
pub fn psubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
sourcepub fn is_subscribed(self: &mut Client, channel: &str) -> bool
pub fn is_subscribed(self: &mut Client, channel: &str) -> bool
Returns true if subscribed to the provided channel.
sourcepub fn is_psubscribed(self: &mut Client, channel: &str) -> bool
pub fn is_psubscribed(self: &mut Client, channel: &str) -> bool
Returns true if subscribed to the provided channel pattern.
sourcepub fn unsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
pub fn unsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel.
sourcepub fn punsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
pub fn punsubscribe(self: &mut Client, channel: &str) -> RedisEmptyResult
Unsubscribes from the provided channel pattern.
sourcepub fn unsubscribe_all(self: &mut Client) -> RedisEmptyResult
pub fn unsubscribe_all(self: &mut Client) -> RedisEmptyResult
Unsubscribes from all channels.
sourcepub fn fetch_messages(
self: &mut Client,
on_message: &mut dyn FnMut(Message) -> bool,
poll_interrupts: &mut dyn FnMut() -> Interrupts
) -> RedisEmptyResult
pub fn fetch_messages( self: &mut Client, on_message: &mut dyn FnMut(Message) -> bool, poll_interrupts: &mut dyn FnMut() -> Interrupts ) -> RedisEmptyResult
Fetches the messages from any of the subscribed channels and invokes the provided
on_message handler.
This function will return an error in case no subscriptions are defined.
This function will block and continue to listen to all messages, until either the
on_message returns true.
Arguments
on_message
- Invoked on each read message. If returns true, the fetching will stop.poll_interrupts
- Returns the interrupts struct, enabling to modify the fetching.
Example
client.subscribe("important_notifications");
// fetch messages from all subscriptions
client.fetch_messages(
&mut |message: simple_redis::Message| -> bool {
let payload : String = message.get_payload().unwrap();
println!("Got message: {}", payload);
// continue fetching
false
},
&mut || -> Interrupts { Interrupts::new() },
).unwrap();
source§impl Client
impl Client
Defines the redis commands exposed by the redis client.
sourcepub fn auth(&mut self, password: &str) -> RedisEmptyResult
pub fn auth(&mut self, password: &str) -> RedisEmptyResult
sourcepub fn echo(&mut self, value: &str) -> RedisStringResult
pub fn echo(&mut self, value: &str) -> RedisStringResult
See redis ECHO command.
sourcepub fn publish(&mut self, channel: &str, message: &str) -> RedisEmptyResult
pub fn publish(&mut self, channel: &str, message: &str) -> RedisEmptyResult
sourcepub fn get_string(self: &mut Client, key: &str) -> RedisStringResult
pub fn get_string(self: &mut Client, key: &str) -> RedisStringResult
sourcepub fn setex<T: RedisArg>(
&mut self,
key: &str,
value: T,
seconds: usize
) -> RedisEmptyResult
pub fn setex<T: RedisArg>( &mut self, key: &str, value: T, seconds: usize ) -> RedisEmptyResult
sourcepub fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult
pub fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult
See redis SETNX command.
sourcepub fn getset<T: RedisArg, V: FromStr>(
&mut self,
key: &str,
value: T
) -> RedisResult<V>
pub fn getset<T: RedisArg, V: FromStr>( &mut self, key: &str, value: T ) -> RedisResult<V>
See redis GETSET command.
sourcepub fn getset_string<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisStringResult
pub fn getset_string<T: RedisArg>( &mut self, key: &str, value: T ) -> RedisStringResult
See redis GETSET command.
sourcepub fn del(&mut self, key: &str) -> RedisEmptyResult
pub fn del(&mut self, key: &str) -> RedisEmptyResult
See redis DEL command.
sourcepub fn exists(&mut self, key: &str) -> RedisBoolResult
pub fn exists(&mut self, key: &str) -> RedisBoolResult
See redis EXISTS command.
sourcepub fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult
pub fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult
See redis EXPIRE command.
sourcepub fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult
pub fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult
See redis PEXPIRE command.
sourcepub fn persist(&mut self, key: &str) -> RedisEmptyResult
pub fn persist(&mut self, key: &str) -> RedisEmptyResult
See redis PERSIST command.
sourcepub fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
pub fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAME command.
sourcepub fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
pub fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult
See redis RENAMENX command.
sourcepub fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64>
pub fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64>
See redis INCRBY command.
sourcepub fn incrbyfloat<T: RedisArg>(
&mut self,
key: &str,
value: T
) -> RedisResult<f64>
pub fn incrbyfloat<T: RedisArg>( &mut self, key: &str, value: T ) -> RedisResult<f64>
See redis INCRBYFLOAT command.
sourcepub fn hget<T: FromStr>(
self: &mut Client,
key: &str,
field: &str
) -> RedisResult<T>
pub fn hget<T: FromStr>( self: &mut Client, key: &str, field: &str ) -> RedisResult<T>
See redis HGET command.
sourcepub fn hget_string(
self: &mut Client,
key: &str,
field: &str
) -> RedisStringResult
pub fn hget_string( self: &mut Client, key: &str, field: &str ) -> RedisStringResult
See redis HGET command.
sourcepub fn hset<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
pub fn hset<T: RedisArg>( self: &mut Client, key: &str, field: &str, value: T ) -> RedisEmptyResult
See redis HSET command.
sourcepub fn hsetnx<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T
) -> RedisEmptyResult
pub fn hsetnx<T: RedisArg>( self: &mut Client, key: &str, field: &str, value: T ) -> RedisEmptyResult
See redis HSETNX command.
sourcepub fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult
pub fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult
See redis HDEL command.
sourcepub fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult
pub fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult
See redis HEXISTS command.
sourcepub fn lset<T: RedisArg>(
self: &mut Client,
key: &str,
index: isize,
value: T
) -> RedisEmptyResult
pub fn lset<T: RedisArg>( self: &mut Client, key: &str, index: isize, value: T ) -> RedisEmptyResult
See redis LSET command.
sourcepub fn lindex<T: FromStr>(
self: &mut Client,
key: &str,
index: isize
) -> RedisResult<T>
pub fn lindex<T: FromStr>( self: &mut Client, key: &str, index: isize ) -> RedisResult<T>
See redis HGET command.
sourcepub fn lindex_string(
self: &mut Client,
key: &str,
index: isize
) -> RedisStringResult
pub fn lindex_string( self: &mut Client, key: &str, index: isize ) -> RedisStringResult
See redis HGET command.
sourcepub fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
pub fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis LPOP command.
sourcepub fn lpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
pub fn lpush<T: RedisArg>( self: &mut Client, key: &str, value: T ) -> RedisEmptyResult
See redis LPUSH command.
sourcepub fn lpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
pub fn lpushx<T: RedisArg>( self: &mut Client, key: &str, value: T ) -> RedisEmptyResult
See redis LPUSHX command.
sourcepub fn lrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisResult<Vec<String>>
pub fn lrange( self: &mut Client, key: &str, start: isize, stop: isize ) -> RedisResult<Vec<String>>
See redis LRANGE command.
sourcepub fn lrem<T: RedisArg>(
self: &mut Client,
key: &str,
count: isize,
value: T
) -> RedisEmptyResult
pub fn lrem<T: RedisArg>( self: &mut Client, key: &str, count: isize, value: T ) -> RedisEmptyResult
See redis LREM command.
sourcepub fn ltrim(
self: &mut Client,
key: &str,
start: isize,
stop: isize
) -> RedisEmptyResult
pub fn ltrim( self: &mut Client, key: &str, start: isize, stop: isize ) -> RedisEmptyResult
See redis LTRIM command.
sourcepub fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
pub fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T>
See redis RPOP command.
sourcepub fn rpush<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
pub fn rpush<T: RedisArg>( self: &mut Client, key: &str, value: T ) -> RedisEmptyResult
See redis RPUSH command.
sourcepub fn rpushx<T: RedisArg>(
self: &mut Client,
key: &str,
value: T
) -> RedisEmptyResult
pub fn rpushx<T: RedisArg>( self: &mut Client, key: &str, value: T ) -> RedisEmptyResult
See redis RPUSHX command.
sourcepub fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32>
pub fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32>
See redis SADD command.
sourcepub fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>>
pub fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>>
See redis SDIFF command.
sourcepub fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult
pub fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult
See redis SISMEMBER command.
sourcepub fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>>
pub fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>>
See redis SMEMBERS command.
sourcepub fn smove(
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str
) -> RedisEmptyResult
pub fn smove( self: &mut Client, source_key: &str, destination_key: &str, member: &str ) -> RedisEmptyResult
See redis SMOVE command.
sourcepub fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult
pub fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult
See redis SREM command.