Created
October 16, 2014 10:18
-
-
Save ik5/a8db0169b975a3f04f76 to your computer and use it in GitHub Desktop.
beanstalk example in go
This file contains hidden or 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" | |
"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) | |
} | |
} | |
} |
This file contains hidden or 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" | |
"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