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=