客户端使用非常简单,提供了 push
、pop
、bPop
、remove
四个方法操作任务。
通过 go get
安装使用:
// install Redis client
go get github.com/gomodule/redigo/redis
// install Delayer client
go get github.com/mix-basic/delayer-client-golang/delayer
通过连接信息创建客户端
cli := delayer.Client{
Host: "127.0.0.1",
Port: "6379",
Database: 0,
Password: "",
}
cli.Init()
通过已有连接创建客户端
pool := redis.Pool{}
conn := pool.Get();
cli := delayer.Client{
Conn:conn,
}
cli.Init()
放入一个任务。
cli := delayer.Client{
Host: "127.0.0.1",
Port: "6379",
Database: 0,
Password: "",
}
cli.Init()
msg := delayer.Message{
ID: fmt.Sprintf("%x", md5.Sum([]byte(time.Now().String()))),
Topic: "test",
Body: "test body",
}
reply, err := cli.Push(msg, 10, 600)
fmt.Println(msg)
fmt.Println(reply)
fmt.Println(err)
取出一个到期的任务。
cli := delayer.Client{
Host: "127.0.0.1",
Port: "6379",
Database: 0,
Password: "",
}
cli.Init()
msg, err := cli.Pop("test");
fmt.Println(msg)
fmt.Println(err)
阻塞取出一个到期的任务。
cli := delayer.Client{
Host: "127.0.0.1",
Port: "6379",
Database: 0,
Password: "",
}
cli.Init()
msg, err := cli.BPop("test", 10);
fmt.Println(msg)
fmt.Println(err)
移除一个未到期的任务。
cli := delayer.Client{
Host: "127.0.0.1",
Port: "6379",
Database: 0,
Password: "",
}
cli.Init()
ok, err := cli.Remove("9a8482a06630840ce7da9da62d748b8a")
fmt.Println(ok)
fmt.Println(err)
Apache License Version 2.0, http://www.apache.org/licenses/