GithubHelp home page GithubHelp logo

bsc's Introduction

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

bsc's People

Contributors

maxleiko avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

bsc's Issues

Ensure invariants for all conn

  • "OUT_OF_MEMORY\r\n" The server cannot allocate enough memory for the job.
    The client should try again later.

  • "INTERNAL_ERROR\r\n" This indicates a bug in the server. It should never
    happen. If it does happen, please report it at
    http://groups.google.com/group/beanstalk-talk.

  • "BAD_FORMAT\r\n" The client sent a command line that was not well-formed.
    This can happen if the line's length exceeds 224 bytes including \r\n,
    if the name of a tube exceeds 200 bytes, if non-numeric
    characters occur where an integer is expected, if the wrong number of
    arguments are present, or if the command line is mal-formed in any other
    way.

  • "UNKNOWN_COMMAND\r\n" The client sent a command that the server does not
    know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.