Skip to content

Instantly share code, notes, and snippets.

@ik5
Created October 16, 2014 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/a8db0169b975a3f04f76 to your computer and use it in GitHub Desktop.
Save ik5/a8db0169b975a3f04f76 to your computer and use it in GitHub Desktop.
beanstalk example in go
package main
import (
"fmt"
"github.com/kr/beanstalk"
"os"
"time"
)
func main() {
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
if err != nil {
fmt.Println("Error connection beanstalkd: ", err)
os.Exit(1)
}
defer c.Close()
for {
id, body, err := c.Reserve(5 * time.Hour)
if err != nil {
fmt.Println("Error on reserve: ", err)
} else {
fmt.Printf("id: %d, body: %s\n", id, body)
}
}
}
package main
import (
"fmt"
"github.com/kr/beanstalk"
"os"
"time"
)
func main() {
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
if err != nil {
fmt.Println("Error connection beanstalkd: ", err)
os.Exit(1)
}
defer c.Close()
for {
t := time.Now().String()
id, err := c.Put([]byte(t), 1, 0, 120*time.Second)
if err != nil {
fmt.Printf("Error using put: %s\n", err)
} else {
fmt.Printf("id: %d, body: %s \n", id, t)
}
time.Sleep(time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment