locker.go 625 B

1234567891011121314151617181920212223242526272829
  1. package runtime
  2. import (
  3. "github.com/bsm/redislock"
  4. "gogs.baozhida.cn/zoie/OAuth-core/storage"
  5. )
  6. // NewLocker 创建对应上下文分布式锁
  7. func NewLocker(prefix string, locker storage.AdapterLocker) storage.AdapterLocker {
  8. return &Locker{
  9. prefix: prefix,
  10. locker: locker,
  11. }
  12. }
  13. type Locker struct {
  14. prefix string
  15. locker storage.AdapterLocker
  16. }
  17. func (e *Locker) String() string {
  18. return e.locker.String()
  19. }
  20. // Lock 返回分布式锁对象
  21. func (e *Locker) Lock(key string, ttl int64, options *redislock.Options) (*redislock.Lock, error) {
  22. return e.locker.Lock(e.prefix+intervalTenant+key, ttl, options)
  23. }