GithubHelp home page GithubHelp logo

wesley-yang / delayer-client-golang-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mix-basic/delayer-client-golang

0.0 0.0 0.0 38 KB

延迟队列中间件 Delayer 的 Golang 客户端

License: Apache License 2.0

Go 100.00%

delayer-client-golang-1's Introduction

Delayer Golang 客户端

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

安装

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/

delayer-client-golang-1's People

Contributors

onanying avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.