定义延迟队列生产者接口以及基于redis的实现

This commit is contained in:
白茶清欢 2022-07-06 18:10:33 +08:00
parent bce2f7159e
commit 436fc2626e
5 changed files with 88 additions and 0 deletions

18
delay/abstract.go Normal file
View File

@ -0,0 +1,18 @@
// Package delay ...
//
// Description : delay ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-06 18:06
package delay
// IProduce 生产者约束
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:06 2022/7/6
type IProduce interface {
// Produce 生产数据
Produce(data *Queue) error
}

19
delay/define.go Normal file
View File

@ -0,0 +1,19 @@
// Package delay ...
//
// Description : delay ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-06 17:55
package delay
// Queue 队列数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:56 2022/7/6
type Queue struct {
Name string `json:"name"` // 队列名称
DelayTime int `json:"delay_time"` // 延迟执行时间
Data map[string]interface{} `json:"data"` // 入队数据
}

39
delay/redis_produce.go Normal file
View File

@ -0,0 +1,39 @@
// Package delay ...
//
// Description : delay ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-06 17:59
package delay
import (
"github.com/go-redis/redis/v8"
)
// NewRedisQueue 获取redis队列实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:09 2022/7/6
func NewRedisQueue(redisInstance *redis.Client) IProduce {
return &redisProduce{client: redisInstance}
}
// withRedis 使用redis实现延迟队列
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:59 2022/7/6
type redisProduce struct {
client *redis.Client
}
// Produce 生产数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:03 2022/7/6
func (rp *redisProduce) Produce(data *Queue) error {
return nil
}

6
go.mod
View File

@ -1,3 +1,9 @@
module git.zhangdeman.cn/zhangdeman/queue module git.zhangdeman.cn/zhangdeman/queue
go 1.17 go 1.17
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
)

6
go.sum Normal file
View File

@ -0,0 +1,6 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=