Skip to content

Commit

Permalink
Merge branch 'master' of https://gopkg.in/go-oauth2/redis.v3
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Dec 19, 2019
2 parents ab8d028 + b02ea38 commit cf90570
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 170 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ $ go get -u -v gopkg.in/go-oauth2/redis.v3
package main

import (
"gopkg.in/go-oauth2/redis.v3"
"github.com/go-redis/redis"
oredis "gopkg.in/go-oauth2/redis.v3"
"gopkg.in/oauth2.v3/manage"
)

func main() {
manager := manage.NewDefaultManager()

// use redis token store
manager.MapTokenStorage(redis.NewRedisStore(&redis.Options{
manager.MapTokenStorage(oredis.NewRedisStore(&redis.Options{
Addr: "127.0.0.1:6379",
DB: 15,
}))

// use redis cluster store
// manager.MapTokenStorage(redis.NewRedisClusterStore(&redis.ClusterOptions{
// manager.MapTokenStorage(oredis.NewRedisClusterStore(&redis.ClusterOptions{
// Addrs: []string{"127.0.0.1:6379"},
// DB: 15,
// }))
Expand Down
157 changes: 0 additions & 157 deletions options.go

This file was deleted.

8 changes: 4 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ var (
)

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

// NewRedisStoreWithCli create an instance of a redis store
Expand All @@ -38,11 +38,11 @@ func NewRedisStoreWithCli(cli *redis.Client, keyNamespace ...string) *TokenStore
}

// NewRedisClusterStore create an instance of a redis cluster store
func NewRedisClusterStore(opts *ClusterOptions) *TokenStore {
func NewRedisClusterStore(opts *redis.ClusterOptions, keyNamespace ...string) *TokenStore {
if opts == nil {
panic("options cannot be nil")
}
return NewRedisClusterStoreWithCli(redis.NewClusterClient(opts.redisClusterOptions()), opts.KeyNamespace)
return NewRedisClusterStoreWithCli(redis.NewClusterClient(opts), keyNamespace...)
}

// NewRedisClusterStoreWithCli create an instance of a redis cluster store
Expand Down
12 changes: 6 additions & 6 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/go-redis/redis"
"gopkg.in/oauth2.v3/models"

. "github.com/smartystreets/goconvey/convey"
Expand All @@ -16,7 +17,7 @@ const (

func TestTokenStore(t *testing.T) {
Convey("Test redis token store", t, func() {
opts := &Options{
opts := &redis.Options{
Addr: addr,
DB: db,
}
Expand Down Expand Up @@ -104,12 +105,11 @@ func TestTokenStore(t *testing.T) {

func TestTokenStoreWithKeyNamespace(t *testing.T) {
Convey("Test redis token store", t, func() {
opts := &Options{
Addr: addr,
DB: db,
KeyNamespace: "test:",
opts := &redis.Options{
Addr: addr,
DB: db,
}
store := NewRedisStore(opts)
store := NewRedisStore(opts, "test:")

Convey("Test authorization code store", func() {
info := &models.Token{
Expand Down

0 comments on commit cf90570

Please sign in to comment.