更新MongoDB配置并优化Redis客户端调用方式
This commit is contained in:
@@ -6,7 +6,9 @@ rate:
|
|||||||
burst: 300
|
burst: 300
|
||||||
mongo:
|
mongo:
|
||||||
default:
|
default:
|
||||||
address: "mongodb://116.204.74.41:27017/oss?retryWrites=true"
|
address: "116.204.74.41:17027"
|
||||||
|
username: "root"
|
||||||
|
password: "M0ng0DB@Pass2026!"
|
||||||
database: "oss"
|
database: "oss"
|
||||||
maxPoolSize: 100
|
maxPoolSize: 100
|
||||||
minPoolSize: 10
|
minPoolSize: 10
|
||||||
|
|||||||
24
main.go
24
main.go
@@ -6,15 +6,11 @@ import (
|
|||||||
"oss/service"
|
"oss/service"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/db/mongo"
|
|
||||||
"gitea.com/red-future/common/log/consts"
|
|
||||||
"gitea.com/red-future/common/message"
|
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
"github.com/gogf/gf/v2/os/gtimer"
|
"github.com/gogf/gf/v2/os/gtimer"
|
||||||
|
|
||||||
"gitea.com/red-future/common/http"
|
"gitea.com/red-future/common/http"
|
||||||
"gitea.com/red-future/common/jaeger"
|
"gitea.com/red-future/common/jaeger"
|
||||||
logService "gitea.com/red-future/common/log/service"
|
|
||||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,16 +31,16 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 启动消息队列消费者
|
// 启动消息队列消费者
|
||||||
if err := message.StartConsumers(ctx, &message.RedisMessageConfig{
|
//if err := message.StartConsumers(ctx, &message.RedisMessageConfig{
|
||||||
StreamKey: mongo.LogRedisKey,
|
// StreamKey: mongo.LogRedisKey,
|
||||||
GroupName: consts.GroupName,
|
// GroupName: consts.GroupName,
|
||||||
ConsumerName: consts.ConsumerName,
|
// ConsumerName: consts.ConsumerName,
|
||||||
BatchSize: consts.BatchSize,
|
// BatchSize: consts.BatchSize,
|
||||||
AutoAck: consts.AutoAck,
|
// AutoAck: consts.AutoAck,
|
||||||
HandleFunc: logService.OperationLog.AddOperationLog,
|
// HandleFunc: logService.OperationLog.AddOperationLog,
|
||||||
}); err != nil {
|
//}); err != nil {
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 保持应用运行
|
// 保持应用运行
|
||||||
select {}
|
select {}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto
|
|||||||
|
|
||||||
success, err := redis.Lock(ctx, fileLockKey, gconv.Int64(time.Minute*1), func(ctx context.Context) error {
|
success, err := redis.Lock(ctx, fileLockKey, gconv.Int64(time.Minute*1), func(ctx context.Context) error {
|
||||||
// 获取redis-租户存储容量总数
|
// 获取redis-租户存储容量总数
|
||||||
get, err := redis.RedisClient.Get(ctx, tenantOssTotalKey)
|
get, err := redis.RedisClient().Get(ctx, tenantOssTotalKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf(ctx, "获取redis-租户存储容量总数失败: %v", err)
|
glog.Errorf(ctx, "获取redis-租户存储容量总数失败: %v", err)
|
||||||
return err
|
return err
|
||||||
@@ -82,7 +82,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto
|
|||||||
Updater: user.UserName,
|
Updater: user.UserName,
|
||||||
}
|
}
|
||||||
// 修改redis-租户存储容量总数 超时时间10分钟
|
// 修改redis-租户存储容量总数 超时时间10分钟
|
||||||
if err = redis.RedisClient.SetEX(ctx, tenantOssTotalKey, tenantOssTotalKeyMap, gconv.Int64(time.Minute*10)); err != nil {
|
if err = redis.RedisClient().SetEX(ctx, tenantOssTotalKey, tenantOssTotalKeyMap, gconv.Int64(time.Minute*10)); err != nil {
|
||||||
glog.Errorf(ctx, "修改redis-租户存储容量总数 超时时间10分钟失败: %v", err)
|
glog.Errorf(ctx, "修改redis-租户存储容量总数 超时时间10分钟失败: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (s *tenantOssTotal) GetOneByTenantId(ctx context.Context, req *dto.GetByTen
|
|||||||
|
|
||||||
func (s *tenantOssTotal) UpdateUsedOssSize(ctx context.Context) (err error) {
|
func (s *tenantOssTotal) UpdateUsedOssSize(ctx context.Context) (err error) {
|
||||||
// 使用 Keys 取出所有key
|
// 使用 Keys 取出所有key
|
||||||
keys, err := redis.RedisClient.Keys(ctx, consts.OssTotalKey)
|
keys, err := redis.RedisClient().Keys(ctx, consts.OssTotalKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user