refactor: Remove Token management and integrate Redis for authentication
- Deleted the Token model and its repository, transitioning to a Redis-based token management system. - Updated the service layer to utilize Redis for token storage, enhancing performance and scalability. - Refactored the container to remove TokenRepository and integrate the new token service. - Cleaned up the Dockerfile and other files by removing unnecessary whitespace and comments. - Enhanced error handling and logging for Redis initialization and usage.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/zap"
|
||||
@@ -99,7 +98,7 @@ func (s *profileService) GetByUUID(ctx context.Context, uuid string) (*model.Pro
|
||||
// 尝试从缓存获取
|
||||
cacheKey := s.cacheKeys.Profile(uuid)
|
||||
var profile model.Profile
|
||||
if err := s.cache.Get(ctx, cacheKey, &profile); err == nil {
|
||||
if ok, _ := s.cache.TryGet(ctx, cacheKey, &profile); ok {
|
||||
return &profile, nil
|
||||
}
|
||||
|
||||
@@ -112,11 +111,9 @@ func (s *profileService) GetByUUID(ctx context.Context, uuid string) (*model.Pro
|
||||
return nil, fmt.Errorf("查询档案失败: %w", err)
|
||||
}
|
||||
|
||||
// 存入缓存(异步,5分钟过期)
|
||||
// 存入缓存(异步)
|
||||
if profile2 != nil {
|
||||
go func() {
|
||||
_ = s.cache.Set(context.Background(), cacheKey, profile2, 5*time.Minute)
|
||||
}()
|
||||
s.cache.SetAsync(context.Background(), cacheKey, profile2, s.cache.Policy.ProfileTTL)
|
||||
}
|
||||
|
||||
return profile2, nil
|
||||
@@ -126,7 +123,7 @@ func (s *profileService) GetByUserID(ctx context.Context, userID int64) ([]*mode
|
||||
// 尝试从缓存获取
|
||||
cacheKey := s.cacheKeys.ProfileList(userID)
|
||||
var profiles []*model.Profile
|
||||
if err := s.cache.Get(ctx, cacheKey, &profiles); err == nil {
|
||||
if ok, _ := s.cache.TryGet(ctx, cacheKey, &profiles); ok {
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
@@ -136,11 +133,9 @@ func (s *profileService) GetByUserID(ctx context.Context, userID int64) ([]*mode
|
||||
return nil, fmt.Errorf("查询档案列表失败: %w", err)
|
||||
}
|
||||
|
||||
// 存入缓存(异步,3分钟过期)
|
||||
// 存入缓存(异步)
|
||||
if profiles != nil {
|
||||
go func() {
|
||||
_ = s.cache.Set(context.Background(), cacheKey, profiles, 3*time.Minute)
|
||||
}()
|
||||
s.cache.SetAsync(context.Background(), cacheKey, profiles, s.cache.Policy.ProfileListTTL)
|
||||
}
|
||||
|
||||
return profiles, nil
|
||||
|
||||
Reference in New Issue
Block a user