Skip to content

An asynchronous Redis client library and a Redis CLI built in Rust and Tokio

License

Notifications You must be signed in to change notification settings

Aden-Q/redis-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-async

An asynchronous Redis client library and a Redis CLI built in Rust and Tokio. Inspired by mini-redis.

Usage

Using the lib

First import dependencies:

# in Cargo.toml
[dependencies.redis-async]
git = "https://github.com/aden-q/redis-async.git"

Then use the lib in your Rust code:

use redis_asyncx::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = Client::connect("127.0.0.1:6379").await?;
    let _ = client.ping(Some("Hello, Redis!")).await?;
    let _ = client.set("mykey", "myvalue").await?;
    let _ = client.get("mykey").await?;

    Ok(())
}

More examples can be found in the examples directory.

Using the CLI

You can install the CLI as a binary or run it with Cargo.

To install as a binary into ~/.cargo/bin:

~ cargo install redis-asyncx

Then you can run it:

~ redis-async-cli

To build and run without installation:

~ cargo build --release --bin redis-async-cli

Then you can run it:

~ ./target/release/redis-async-cli

To use the CLI, you first need to run a Redis server. Then you can run this CLI in either interactive mode or command line mode:

  • Interactive mode:

In interactive mode, commands are case insensitive, but arguments are not, which means, Ping, ping, PING they refer to the same Redis command.

> redis-async-cli
Interactive mode. Type 'exit' to quit.
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set key value    
OK
127.0.0.1:6379> get key
"value"
  • Command line mode:
~ redis-async-cli ping
PONG
~ redis-async-cli set key value
OK
~ redis-async-cli get key
"value"

For all available commands and options:

~ redis-async-cli -h

TLS/SSL

TBD. Not available yet.

Connection pooling

TBD. Not available yet.

RESP2/RESP3

Both RESP2 and RESP3 are supported. A protocol is set per connection. By default, the connection runs in RESP2 mode. There is a HELLO command you can use to switch between different protocols.

Examples:

  • CLI

Switch to RESP3:

~ redis-async-cli hello 3

Switc back to RESP2:

~ redis-async-cli hello 2
  • Lib
use redis_async::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = Client::connect("127.0.0.1:6379").await?;
    // switch to RESP3
    let _ = client.hello(Some(3));
    // swtich back to RESP2 (default)
    let _ = client.hello(Some(2));

    Ok(())
}

Supported commands

This library is more on prototype. More commands will be added later on.

Development

Local build

To build the lib:

~ cargo build --lib

To build the CLI:

~ cargo build --bin redis-async-cli

For just users, refer to the local justfile for a list of targets:

~ just -l

Docs

~ cargo doc --no-deps --open

License

The project is licensed under the MIT license.

About

An asynchronous Redis client library and a Redis CLI built in Rust and Tokio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published