redis_lock_project.go
414 字节
package xredis
import (
"fmt"
"github.com/go-redsync/redsync/v4"
)
type LockProjectId struct {
m *redsync.Mutex
}
func NewLockProjectId(id int) *LockProjectId {
key := fmt.Sprintf("performance:project_id:%d", id)
return &LockProjectId{
m: rsync.NewMutex(key),
}
}
func (lk *LockProjectId) Lock() error {
return lk.m.Lock()
}
func (lk *LockProjectId) UnLock() (bool, error) {
return lk.m.Unlock()
}