Struct simple_redis::client::Client[][src]

pub struct Client { /* fields omitted */ }
Expand description

The redis client which enables to invoke redis operations.

Implementations

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.

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.")
}

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"),
}

invokes the run_command and returns typed result

invokes the run_command but returns empty result

invokes the run_command but returns string result

invokes the run_command but returns bool result

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");

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*");

Returns true if subscribed to the provided channel.

Returns true if subscribed to the provided channel pattern.

Unsubscribes from the provided channel.

Unsubscribes from the provided channel pattern.

Unsubscribes from all channels.

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();

Defines the redis commands exposed by the redis client.

See redis AUTH command.

Example

          match client.auth("my_password") {
              Err(error) => println!("Auth error: {}", error),
              _ => println!("Authenticated")
          }

See redis ECHO command.

See redis PUBLISH command.

Example

match client.publish("important_notifications", "message text") {
  Err(error) => println!("Publish error: {}", error),
  _ => println!("Message published")
}

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)
}

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)
}

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")
}

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")
}

See redis SETNX command.

See redis GETSET command.

See redis GETSET command.

See redis DEL command.

See redis EXISTS command.

See redis EXPIRE command.

See redis PEXPIRE command.

See redis PERSIST command.

See redis RENAME command.

See redis RENAMENX command.

See redis APPEND command.

See redis INCR command.

See redis INCRBY command.

See redis INCRBYFLOAT command.

See redis STRLEN command.

See redis KEYS command.

See redis HGET command.

See redis HGET command.

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),
}

See redis HSET command.

See redis HSETNX command.

See redis HDEL command.

See redis HEXISTS command.

See redis HKEYS command.

See redis HVALS command.

See redis LSET command.

See redis HGET command.

See redis HGET command.

See redis LLEN command.

See redis LPOP command.

See redis LPUSH command.

See redis LPUSHX command.

See redis LRANGE command.

See redis LREM command.

See redis LTRIM command.

See redis RPOP command.

See redis RPUSH command.

See redis RPUSHX command.

See redis SADD command.

See redis SCARD command.

See redis SDIFF command.

See redis SISMEMBER command.

See redis SMEMBERS command.

See redis SMOVE command.

See redis SREM command.

See redis ZADD command.

See redis ZRANGE command.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.