feat 修改usn类型为string
This commit is contained in:
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-user/internal/dao/model"
|
||||
@@ -10,11 +9,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
cacheBySn = "c:user:s:%v"
|
||||
cacheByPhone = "c:user:p:%v"
|
||||
)
|
||||
|
||||
type UserDao struct {
|
||||
ctx context.Context
|
||||
query *query.Query
|
||||
@@ -24,7 +18,7 @@ type UserDao struct {
|
||||
func NewUserDao(ctx context.Context, cache ...*redis.CacheClient) *UserDao {
|
||||
dao := &UserDao{
|
||||
ctx: ctx,
|
||||
query: query.Use(mysql.GetDB("user_db")),
|
||||
query: query.Use(mysql.GetDB(dbName)),
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
@@ -44,17 +38,17 @@ func (d *UserDao) Updates(user *model.User) error {
|
||||
Updates(user)
|
||||
if info.RowsAffected > 0 {
|
||||
if d.cache != nil {
|
||||
d.cache.Del(d.ctx, fmt.Sprintf(cacheBySn, user.Sn))
|
||||
d.cache.Del(d.ctx, fmt.Sprintf(cacheByPhone, user.Phone))
|
||||
d.cache.Del(d.ctx, keyCacheBySn(user.Sn, user.TableName()))
|
||||
d.cache.Del(d.ctx, keyUserCacheByPhone(user.Phone))
|
||||
}
|
||||
}
|
||||
return info.Error
|
||||
}
|
||||
|
||||
func (d *UserDao) FindBySn(sn int64) (*model.User, error) {
|
||||
func (d *UserDao) FindBySn(sn string) (*model.User, error) {
|
||||
if d.cache != nil {
|
||||
var user model.User
|
||||
if ok := d.cache.Get(d.ctx, fmt.Sprintf(cacheBySn, sn), &user); ok {
|
||||
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, user.TableName()), &user); ok {
|
||||
return &user, nil
|
||||
}
|
||||
}
|
||||
@@ -65,7 +59,7 @@ func (d *UserDao) FindBySn(sn int64) (*model.User, error) {
|
||||
return nil, err
|
||||
}
|
||||
if d.cache != nil {
|
||||
d.cache.Set(d.ctx, fmt.Sprintf(cacheBySn, sn), first, 5*time.Minute)
|
||||
d.cache.Set(d.ctx, keyCacheBySn(sn, first.TableName()), first, 5*time.Minute)
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
@@ -73,7 +67,7 @@ func (d *UserDao) FindBySn(sn int64) (*model.User, error) {
|
||||
func (d *UserDao) FindByPhone(phone string) (*model.User, error) {
|
||||
if d.cache != nil {
|
||||
var user model.User
|
||||
if ok := d.cache.Get(d.ctx, fmt.Sprintf(cacheByPhone, phone), &user); ok {
|
||||
if ok := d.cache.Get(d.ctx, keyUserCacheByPhone(phone), &user); ok {
|
||||
return &user, nil
|
||||
}
|
||||
}
|
||||
@@ -84,7 +78,7 @@ func (d *UserDao) FindByPhone(phone string) (*model.User, error) {
|
||||
return nil, err
|
||||
}
|
||||
if d.cache != nil {
|
||||
d.cache.Set(d.ctx, fmt.Sprintf(cacheByPhone, phone), first, 5*time.Minute)
|
||||
d.cache.Set(d.ctx, keyUserCacheByPhone(phone), first, 5*time.Minute)
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user