蛋蛋星球-制度模式
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
655 B

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