Created
March 14, 2014 06:48
-
-
Save larryli/9543106 to your computer and use it in GitHub Desktop.
Golang beanstalk test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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