GithubHelp home page GithubHelp logo

pjjw / beanstalk.go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kr/beanstalk.go

1.0 2.0 0.0 148 KB

Client library for beanstalkd, written in Go.

Home Page: http://kr.github.com/beanstalk.go/

License: MIT License

beanstalk.go's Introduction

beanstalk.go

beanstalk.go is a client library for the protocol used by beanstalkd.

Installation

No need for that. Just put import "github.com/kr/beanstalk.go.git" at the top of your go package, and install your own package with goinstall.

Overview

To open a connection, do

conn, err := beanstalk.Dial("localhost:11300")

This package provides a simple, blocking interface. Go makes it easy to add asynchrony if you want.

Common Case: To submit a job and get its id, do

id, err := conn.Put(...)

Fire and Forget: If you don't care about the id, no need to wait around:

go conn.Put(...)

Full Asynchrony: If you don't want to wait but still need the id, it's still easy:

go func() {
  id, err := conn.Put(...)
}()

Concurrency and Optimizations

You can perform operations on the queue at will from all goroutines. This package will issue commands to beanstalkd and return results to where they belong. It'll also optimize the commands a bit to reduce network traffic.

For example, the use, watch, and ignore commands are managed entirely by this library, and issued only as necessary.

It also collects as many outbound commands as possible into a single network packet, for efficiency.

In the future, it will manage the order of outgoing commands to further reduce the need for use, watch, and ignore commands, and to prevent reserve commands from stalling other commands unnecessarily.

Complete Example

A producer:

package main

import "github.com/kr/beanstalk.go.git"

func main() {
    conn, err := beanstalk.Dial("localhost:11300")
    conn.Put("hello", 0, 0, 10)
}

And a worker:

package main

import "github.com/kr/beanstalk.go.git"

func main() {
    conn, err := beanstalk.Dial("localhost:11300")
    for {
        j, err := conn.Reserve()
        fmt.Println(j.Body) // prints "hello"
        j.Delete()
    }
}

Contributing

  1. Fix a bug or implement a new feature.
  2. Add tests verifying your change.
  3. Publish your changes in a public git repository. At most one feature or bug fix per commit. Topic branches are preferred, especially for larger changes.
  4. Send me email with the URL of your repository and the branch(es) you want pulled.

Credit Where It's Due

  • spymemcached for the idea of making optimizing transformations on the command stream.

  • Go's standard libraries, especially net and http, for inspiration and guidance.

beanstalk.go's People

Contributors

kr avatar

Stargazers

peter woodman avatar

Watchers

James Cloos avatar  avatar

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.