package svc import ( "errors" "fmt" ) // HandleDistributedLockForVideo 处理短视频更新时获取锁和释放锁 如果加锁成功,使用语句 ` defer cb() ` 释放锁 func HandleDistributedLockForComm(uid, fix, requestIdPrefix string) (cb func(), err error) { // 获取虚拟币更新锁 balanceLockKey := fmt.Sprintf(fix, uid) requestId := GetDistributedLockRequestId(requestIdPrefix) balanceLockOk := TryGetDistributedLock(balanceLockKey, requestId, true) if !balanceLockOk { return nil, errors.New("系统繁忙,请稍后再试") } cb = func() { _, _ = ReleaseDistributedLock(balanceLockKey, requestId) } return cb, nil }