support go-redis/v9

This commit is contained in:
finley
2023-06-27 06:52:00 +08:00
parent 455a9ab414
commit 4cae62d624
7 changed files with 18 additions and 8 deletions

View File

@@ -25,13 +25,15 @@ DelayQueue requires a Go version with modules support. Run following command lin
go get github.com/hdt3213/delayqueue
```
> if you are using github.com/go-redis/redis/v8 please use `go get github.com/hdt3213/delayqueue@v8`
## Get Started
```go
package main
import (
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/hdt3213/delayqueue"
"strconv"
"time"

View File

@@ -21,13 +21,15 @@ DelayQueue 的主要优势:
go get github.com/hdt3213/delayqueue
```
> 如果您仍在使用 `github.com/go-redis/redis/v8` 请安装 `go get github.com/hdt3213/delayqueue@v8`
# 开始使用
```go
package main
import (
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/hdt3213/delayqueue"
"strconv"
"time"

View File

@@ -3,8 +3,8 @@ package delayqueue
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/google/uuid"
"github.com/redis/go-redis/v9"
"log"
"sync"
"time"
@@ -179,7 +179,7 @@ func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interf
return fmt.Errorf("store retry count failed: %v", err)
}
// put to pending
err = q.redisCli.ZAdd(ctx, q.pendingKey, &redis.Z{Score: float64(t.Unix()), Member: idStr}).Err()
err = q.redisCli.ZAdd(ctx, q.pendingKey, redis.Z{Score: float64(t.Unix()), Member: idStr}).Err()
if err != nil {
return fmt.Errorf("push to pending failed: %v", err)
}
@@ -340,7 +340,7 @@ func (q *DelayQueue) ack(idStr string) error {
func (q *DelayQueue) nack(idStr string) error {
ctx := context.Background()
// update retry time as now, unack2Retry will move it to retry immediately
err := q.redisCli.ZAdd(ctx, q.unAckKey, &redis.Z{
err := q.redisCli.ZAdd(ctx, q.unAckKey, redis.Z{
Member: idStr,
Score: float64(time.Now().Unix()),
}).Err()

View File

@@ -2,7 +2,7 @@ package delayqueue
import (
"context"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"log"
"os"
"strconv"

View File

@@ -1,8 +1,8 @@
package main
import (
"github.com/go-redis/redis/v8"
"github.com/hdt3213/delayqueue"
"github.com/redis/go-redis/v9"
"strconv"
"time"
)

2
go.mod
View File

@@ -3,6 +3,6 @@ module github.com/hdt3213/delayqueue
go 1.16
require (
github.com/go-redis/redis/v8 v8.11.4
github.com/google/uuid v1.3.0
github.com/redis/go-redis/v9 v9.0.5 // indirect
)

6
go.sum
View File

@@ -1,5 +1,9 @@
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
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/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -39,6 +43,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=