refactor: 将分布式锁从 redis 迁移至 utils 包

This commit is contained in:
2026-03-27 09:49:44 +08:00
parent 018d60469a
commit b9ed1b2492
4 changed files with 7 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ import (
"gitea.com/red-future/common/db/mongo"
"gitea.com/red-future/common/jaeger"
"gitea.com/red-future/common/redis"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"go.mongodb.org/mongo-driver/v2/bson"
@@ -36,7 +36,7 @@ func (s *capacity) UpdateLocationCapacity(ctx context.Context, locationId *bson.
var zoneId *bson.ObjectID
var capacityUnitType stock.CapacityUnitType
success, err := redis.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
success, err := utils.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
// 1. 查询库位信息
location, err := dao.Location.GetOne(ctx, &dto.GetLocationReq{Id: locationId})
if err != nil {
@@ -179,7 +179,7 @@ func (s *capacity) SyncCapacityToZone(ctx context.Context, zoneId *bson.ObjectID
lockKey := fmt.Sprintf("lock:zone:%s:capacity:%s", zoneId.Hex(), unitType)
expireSeconds := int64(30) // 30秒超时
success, err := redis.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
success, err := utils.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
// 2. 查询该库区下所有使用该单位类型的库位
locations, err := dao.Location.ListByZoneAndUnitType(ctx, zoneId, unitType)
if err != nil {
@@ -242,7 +242,7 @@ func (s *capacity) SyncCapacityToWarehouse(ctx context.Context, warehouseId *bso
lockKey := fmt.Sprintf("lock:warehouse:%s:capacity:%s", warehouseId.Hex(), unitType)
expireSeconds := int64(30) // 30秒超时
success, err := redis.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
success, err := utils.Lock(ctx, lockKey, expireSeconds, func(ctx context.Context) error {
// 2. 查询该仓库下所有库区
zones, err := dao.Zone.ListByWarehouseAndUnitType(ctx, warehouseId.Hex())
if err != nil {