From 436fc2626e5ade198698b7edc83a66169b63c3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 6 Jul 2022 18:10:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=BB=B6=E8=BF=9F=E9=98=9F?= =?UTF-8?q?=E5=88=97=E7=94=9F=E4=BA=A7=E8=80=85=E6=8E=A5=E5=8F=A3=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=9F=BA=E4=BA=8Eredis=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- delay/abstract.go | 18 ++++++++++++++++++ delay/define.go | 19 +++++++++++++++++++ delay/redis_produce.go | 39 +++++++++++++++++++++++++++++++++++++++ go.mod | 6 ++++++ go.sum | 6 ++++++ 5 files changed, 88 insertions(+) create mode 100644 delay/abstract.go create mode 100644 delay/define.go create mode 100644 delay/redis_produce.go create mode 100644 go.sum diff --git a/delay/abstract.go b/delay/abstract.go new file mode 100644 index 0000000..9966067 --- /dev/null +++ b/delay/abstract.go @@ -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 +} diff --git a/delay/define.go b/delay/define.go new file mode 100644 index 0000000..944a00c --- /dev/null +++ b/delay/define.go @@ -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"` // 入队数据 +} diff --git a/delay/redis_produce.go b/delay/redis_produce.go new file mode 100644 index 0000000..f8e1672 --- /dev/null +++ b/delay/redis_produce.go @@ -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 +} diff --git a/go.mod b/go.mod index 1346944..acc6ec9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,9 @@ module git.zhangdeman.cn/zhangdeman/queue 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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8dfa85a --- /dev/null +++ b/go.sum @@ -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=