Skip to content

Upgraded go-redis to v9 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REDIS_HOST="redis"
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ $ go get -u -v github.com/go-oauth2/redis/v4
package main

import (
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
oredis "github.com/go-oauth2/redis/v4"
"github.com/go-oauth2/oauth2/v4/manage"
)
@@ -36,6 +36,11 @@ func main() {
}
```

## Testing

Testing requires a redis db. If you already have one, go ahead and run `go test ./...` like normal.
If you don't already have one, or don't want to use it, you can run in docker with `docker compose run --rm test && docker compose down`.

## MIT License

```
@@ -51,4 +56,4 @@ Copyright (c) 2020 Lyric
[godoc-url]: https://godoc.org/github.com/go-oauth2/redis/v4
[godoc-image]: https://godoc.org/github.com/go-oauth2/redis/v4?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg
[license-image]: https://img.shields.io/npm/l/express.svg
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"
services:
test:
image: golang
env_file: .test.env
depends_on:
redis:
condition: service_healthy
volumes:
- ./:/src
working_dir: /src
command: ["go", "test", "./..."]

redis:
image: redis:7
expose:
- "6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
start_period: 1s
interval: 3s
timeout: 1s
retries: 10
command:
["redis-server", "--loglevel warning"]
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -4,10 +4,9 @@ go 1.13

require (
github.com/go-oauth2/oauth2/v4 v4.1.0
github.com/go-redis/redis/v8 v8.0.0-beta.5
github.com/google/uuid v1.1.1
github.com/json-iterator/go v1.1.10
github.com/google/uuid v1.1.2
github.com/json-iterator/go v1.1.11
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/smartystreets/goconvey v1.6.4
github.com/redis/go-redis/v9 v9.0.5
github.com/smartystreets/goconvey v1.8.0
)
575 changes: 515 additions & 60 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ import (

"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/models"
"github.com/go-redis/redis/v8"
"github.com/google/uuid"
jsoniter "github.com/json-iterator/go"
"github.com/redis/go-redis/v9"
)

var (
@@ -19,15 +19,15 @@ var (
)

// NewRedisStore create an instance of a redis store
func NewRedisStore(opts *redis.Options, keyNamespace ...string) *TokenStore {
func NewRedisStore(opts *redis.UniversalOptions, keyNamespace ...string) *TokenStore {
if opts == nil {
panic("options cannot be nil")
}
return NewRedisStoreWithCli(redis.NewClient(opts), keyNamespace...)
return NewRedisStoreWithCli(redis.NewUniversalClient(opts), keyNamespace...)
}

// NewRedisStoreWithCli create an instance of a redis store
func NewRedisStoreWithCli(cli *redis.Client, keyNamespace ...string) *TokenStore {
func NewRedisStoreWithCli(cli redis.UniversalClient, keyNamespace ...string) *TokenStore {
store := &TokenStore{
cli: cli,
}
34 changes: 25 additions & 9 deletions redis_test.go
Original file line number Diff line number Diff line change
@@ -2,25 +2,41 @@ package redis

import (
"context"
"fmt"
"os"
"testing"
"time"

"github.com/go-oauth2/oauth2/v4/models"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"

. "github.com/smartystreets/goconvey/convey"
)

const (
addr = "localhost:6379"
var (
host = os.Getenv("REDIS_HOST") //"redis:6379"
port = os.Getenv("REDIS_PORT") //"redis:6379"
addr = fmt.Sprintf("%s:%s", host, port)
db = 15
)

func init() {
// default the redis host and port
if host == "" {
host = "localhost"
addr = fmt.Sprintf("%s:%s", host, port)
}
if port == "" {
port = "6379"
addr = fmt.Sprintf("%s:%s", host, port)
}
}

func TestTokenStore(t *testing.T) {
Convey("Test redis token store", t, func() {
opts := &redis.Options{
Addr: addr,
DB: db,
opts := &redis.UniversalOptions{
Addrs: []string{addr},
DB: db,
}
store := NewRedisStore(opts)
ctx := context.Background()
@@ -108,9 +124,9 @@ func TestTokenStore(t *testing.T) {
func TestTokenStoreWithKeyNamespace(t *testing.T) {
ctx := context.Background()
Convey("Test redis token store", t, func() {
opts := &redis.Options{
Addr: addr,
DB: db,
opts := &redis.UniversalOptions{
Addrs: []string{addr},
DB: db,
}
store := NewRedisStore(opts, "test:")