delayer

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Example

例子

package main

import (
	"delayer-client-golang/delayer"
	"github.com/gomodule/redigo/redis"
)

func main() {
	// 通过连接信息创建客户端
	cli := delayer.Client{
		Host:     "127.0.0.1",
		Port:     "6379",
		Database: 0,
		Password: "",
	}
	cli.Init()

	// 通过已有连接创建客户端
	pool := redis.Pool{}
	conn := pool.Get()
	cli1 := delayer.Client{
		Conn: conn,
	}
	cli1.Init()
}
Output:

Index

Examples

Constants

View Source
const (
	KEY_JOB_POOL       = "delayer:job_pool"
	PREFIX_JOB_BUCKET  = "delayer:job_bucket:"
	PREFIX_READY_QUEUE = "delayer:ready_queue:"
)

键名

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn     redis.Conn
	Host     string
	Port     string
	Database int
	Password string
}

客户端结构

func (*Client) BPop

func (p *Client) BPop(topic string, timeout int) (*Message, error)

阻塞取出任务

Example

BPop 例子

package main

import (
	"delayer-client-golang/delayer"
	"fmt"
)

func main() {
	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)
}
Output:

func (*Client) Init

func (p *Client) Init() error

初始化

func (*Client) Pop

func (p *Client) Pop(topic string) (*Message, error)

取出任务

Example

Pop 例子

package main

import (
	"delayer-client-golang/delayer"
	"fmt"
)

func main() {
	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)
}
Output:

func (*Client) Push

func (p *Client) Push(message Message, delayTime int, readyMaxLifetime int) (bool, error)

增加任务

Example

Push 例子

package main

import (
	"crypto/md5"
	"delayer-client-golang/delayer"
	"fmt"
	"time"
)

func main() {
	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)
}
Output:

func (*Client) Remove

func (p *Client) Remove(id string) (bool, error)

移除任务

Example

Remove 例子

package main

import (
	"delayer-client-golang/delayer"
	"fmt"
)

func main() {
	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)
}
Output:

type Message

type Message struct {
	ID    string
	Topic string
	Body  string
}

消息结构

func (*Message) Valid

func (p *Message) Valid() bool

效验

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL