Skip to content

Latest commit

 

History

History
99 lines (80 loc) · 2.14 KB

README.md

File metadata and controls

99 lines (80 loc) · 2.14 KB

bsc

A complete beanstalkd client library and CLI.

The bsc crate implements every commands defined in protocol.txt, while bsc-cli leverages clap to provide a user-friendly command-line interface (CLI).

Docs

Example

[dependencies]
bsc = { version = "0.2.0" }

Then, on your main.rs:

use bsc::{Beanstalk, PutResponse, ReserveResponse};

fn main() {
    let mut bsc = Beanstalk::connect("172.21.0.2:11300").unwrap();

    let res = bsc
        .put(
            0,
            Duration::from_secs(0),
            Duration::from_secs(15),
            b"hello beanstalkd",
        )
        .unwrap();

    if let PutResponse::Inserted(id) = res {
        println!("New job inserted successfully: {id}");

        let res = bsc.reserve(None).unwrap();

        if let ReserveResponse::Reserved { id, data } = res {
            println!("id   = {id}");
            println!("data = {}", std::str::from_utf8(&data).unwrap());
        }

        bsc.delete(id).unwrap();
    }
}

Considering your Beanstalkd instance if available at 172.21.0.2:11300 and has already 41 jobs in queue, you should see:

New job inserted successfully: 42
id   = 42
data = hello beanstalkd

CLI Example

The same example as the above, but using the bsc CLI.

First, lets set the Beanstalkd endpoint once and for all, so that we don't have to -a 172.21.0.2:11300 for each command:

export BEANSTALKD="172.21.0.2:11300"

Then, put:

echo -n "hello beanstalkd" | bsc put --ttr 15
Inserted(42)

Then, reserve:

bsc reserve
{
    "id": 42,
    "data": "hello beanstalkd"
}

Optionally, you can specify -d to the command, to only print the data of the job:

bsc reserve -d
hello beanstalkd

Then, delete:

bsc delete 42
Deleted

TODO/Limitations

  • TESTS§
  • consider return exit != 0 when not happy path