Skip to content

Instantly share code, notes, and snippets.

@larryli
Created March 14, 2014 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save larryli/9543106 to your computer and use it in GitHub Desktop.
Save larryli/9543106 to your computer and use it in GitHub Desktop.
Golang beanstalk test
package main
import (
"fmt"
. "gist.github.com/9521299.git"
"github.com/kr/beanstalk"
"time"
)
func main() {
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
Die(err)
defer c.Close()
c.Tube.Name = "test"
ts := beanstalk.NewTubeSet(c, c.Tube.Name)
id, body, err := ts.Reserve(5 * time.Second)
if cerr, ok := err.(beanstalk.ConnError); ok && cerr.Err == beanstalk.ErrTimeout {
fmt.Println("Reserve", c.Tube.Name, "Timed out")
} else {
Die(err)
fmt.Println("Reserve", c.Tube.Name, id, string(body))
c.Touch(id)
fmt.Println("Touch", id)
time.Sleep(5 * time.Second)
fmt.Println("Touch", id)
time.Sleep(5 * time.Second)
c.Delete(id)
fmt.Println("Delete", id)
}
}
package main
import (
"fmt"
. "gist.github.com/9521299.git"
"github.com/kr/beanstalk"
"time"
)
func main() {
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
Die(err)
defer c.Close()
c.Tube.Name = "test"
s := "hello"
id, err := c.Put([]byte(s), 1, 0, 10*time.Second)
Die(err)
fmt.Println("Put", c.Tube.Name, id, s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment