Module rustis::commands

source ·
Expand description

Define Redis built-in commands in a set of traits

§Built-in commands

Because Redis offers hundreds of commands, in rustis commands have been split in several traits that gather commands by groups, most of the time, groups describe in Redis official documentation.

Depending on the group of commands, traits will be implemented by Client, Pipeline, Transaction or some of these structs.

These is the list of existing command traits:

Redis Stack commands:

§Example

To use a command, simply add the related trait to your use declerations and call the related associated function directly to a client, pipeline, transaction instance.

Commands can be directly awaited or forgotten.

use rustis::{
    client::{Client, ClientPreparedCommand}, 
    commands::{ListCommands, SortedSetCommands, ZAddOptions},
    Result,
};

#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async-std-runtime", async_std::main)]
async fn main() -> Result<()> {
    let client = Client::connect("127.0.0.1:6379").await?;

    // Send & await ListCommands::lpush command
    let _size = client.lpush("mylist", ["element1", "element2"]).await?;

    // Send & forget SortedSetCommands::zadd command
    let _size = client.zadd(
        "mySortedSet",
        [(1.0, "member1"), (2.0, "member2")],
        ZAddOptions::default()
    ).forget();

    Ok(())
}

§Documentation disclaimer

The commands traits documentation is directly adapated from the official Redis documentation found here with the following COPYRIGHT.

Structs§

Enums§

Traits§

Functions§

Type Aliases§