Skip to content
延迟队列中间件 Delayer 的 Golang 客户端
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
delayer
vendor/github.com/gomodule/redigo
.gitignore
Gopkg.lock
Gopkg.toml
LICENSE 第一次提交 Oct 24, 2018
README.md

README.md

Delayer Golang 客户端

客户端使用非常简单,提供了 pushpopbPopremove 四个方法操作任务。

安装

通过 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

Documentation

Example

创建客户端

通过连接信息创建客户端

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()

push 方法

放入一个任务。

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)

pop 方法

取出一个到期的任务。

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)

bPop 方法

阻塞取出一个到期的任务。

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)

remove 方法

移除一个未到期的任务。

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)

License

Apache License Version 2.0, http://www.apache.org/licenses/

You can’t perform that action at this time.