未验证 提交 c666879d 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

Merge pull request #579 from songzhibin97/gva_gormv2_dev

fix:修改redis包,使用推荐的v8
......@@ -9,7 +9,7 @@ import (
"gin-vue-admin/config"
"github.com/go-redis/redis"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
"gorm.io/gorm"
)
......
......@@ -20,8 +20,8 @@ require (
github.com/go-openapi/swag v0.19.8 // indirect
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/go-redis/redis v6.15.7+incompatible
github.com/go-redis/redis/v8 v8.11.0
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2 // indirect
github.com/gookit/color v1.3.1
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
......@@ -31,8 +31,6 @@ require (
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/qiniu/api.v7/v7 v7.4.1
......@@ -52,10 +50,8 @@ require (
go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect
google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gorm.io/driver/mysql v1.0.1
gorm.io/gorm v1.20.7
)
package initialize
import (
"context"
"gin-vue-admin/global"
"github.com/go-redis/redis"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)
......@@ -13,7 +15,7 @@ func Redis() {
Password: redisCfg.Password, // no password set
DB: redisCfg.DB, // use default DB
})
pong, err := client.Ping().Result()
pong, err := client.Ping(context.Background()).Result()
if err != nil {
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
} else {
......
package service
import (
"context"
"errors"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
//@author: [piexlmax](https://github.com/piexlmax)
......@@ -38,7 +40,7 @@ func IsBlacklist(jwt string) bool {
//@return: err error, redisJWT string
func GetRedisJWT(userName string) (err error, redisJWT string) {
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
redisJWT, err = global.GVA_REDIS.Get(context.Background(), userName).Result()
return err, redisJWT
}
......@@ -51,6 +53,6 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
func SetRedisJWT(jwt string, userName string) (err error) {
// 此处过期时间等于jwt过期时间
timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second
err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
err = global.GVA_REDIS.Set(context.Background(), userName, jwt, timer).Err()
return err
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册