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.

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.

impl Client
[src]

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.

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

Unsubscribes from the provided channel.

Unsubscribes from the provided channel pattern.

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