From b2c50502ceb687da5e7857583b0cf4b660047c0d Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Fri, 27 Feb 2026 08:59:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0MongoDB=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96Redis=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml | 4 +++- main.go | 24 ++++++++++-------------- service/file_service.go | 4 ++-- service/tenant_oss_total_service.go | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/config.yml b/config.yml index 3dea488..cb4801b 100644 --- a/config.yml +++ b/config.yml @@ -6,7 +6,9 @@ rate: burst: 300 mongo: default: - address: "mongodb://116.204.74.41:27017/oss?retryWrites=true" + address: "116.204.74.41:17027" + username: "root" + password: "M0ng0DB@Pass2026!" database: "oss" maxPoolSize: 100 minPoolSize: 10 diff --git a/main.go b/main.go index a66da44..d0b35fa 100644 --- a/main.go +++ b/main.go @@ -6,15 +6,11 @@ import ( "oss/service" "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/gtimer" "gitea.com/red-future/common/http" "gitea.com/red-future/common/jaeger" - logService "gitea.com/red-future/common/log/service" _ "github.com/gogf/gf/contrib/nosql/redis/v2" ) @@ -35,16 +31,16 @@ func main() { }) // 启动消息队列消费者 - if err := message.StartConsumers(ctx, &message.RedisMessageConfig{ - StreamKey: mongo.LogRedisKey, - GroupName: consts.GroupName, - ConsumerName: consts.ConsumerName, - BatchSize: consts.BatchSize, - AutoAck: consts.AutoAck, - HandleFunc: logService.OperationLog.AddOperationLog, - }); err != nil { - return - } + //if err := message.StartConsumers(ctx, &message.RedisMessageConfig{ + // StreamKey: mongo.LogRedisKey, + // GroupName: consts.GroupName, + // ConsumerName: consts.ConsumerName, + // BatchSize: consts.BatchSize, + // AutoAck: consts.AutoAck, + // HandleFunc: logService.OperationLog.AddOperationLog, + //}); err != nil { + // return + //} // 保持应用运行 select {} diff --git a/service/file_service.go b/service/file_service.go index 237b74d..726b839 100644 --- a/service/file_service.go +++ b/service/file_service.go @@ -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 { // 获取redis-租户存储容量总数 - get, err := redis.RedisClient.Get(ctx, tenantOssTotalKey) + get, err := redis.RedisClient().Get(ctx, tenantOssTotalKey) if err != nil { glog.Errorf(ctx, "获取redis-租户存储容量总数失败: %v", err) return err @@ -82,7 +82,7 @@ func (f *file) UploadFile(ctx context.Context, req *dto.UploadFileReq) (res *dto Updater: user.UserName, } // 修改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) return err } diff --git a/service/tenant_oss_total_service.go b/service/tenant_oss_total_service.go index c57af1c..6b160b7 100644 --- a/service/tenant_oss_total_service.go +++ b/service/tenant_oss_total_service.go @@ -27,7 +27,7 @@ func (s *tenantOssTotal) GetOneByTenantId(ctx context.Context, req *dto.GetByTen func (s *tenantOssTotal) UpdateUsedOssSize(ctx context.Context) (err error) { // 使用 Keys 取出所有key - keys, err := redis.RedisClient.Keys(ctx, consts.OssTotalKey) + keys, err := redis.RedisClient().Keys(ctx, consts.OssTotalKey) if err != nil { return }