go-zero
go-zero copied to clipboard
the owner can be passed in the function parameter of the RedisLock constructor
Is your feature request related to a problem? Please describe.
- Random number generation requires a certain cost, so the current implementation of distributed locks may not perform well in high concurrency situations
- At same time, in some cases (exactly what I have encountered so far), the owner may just be the process id or other fixed value
Describe the solution you'd like
- improved RedisLock constructor using "option" style
type Option func(*RedisLock)
func WithOwner(owner string) Option {
return func(lock *RedisLock) {
lock.owner = owner
}
}
func WithExpireAt(expire time.Time) Option {
return func(lock *RedisLock) {
lock.expiredAt = expire
}
}
func NewRedisLock(key string, options ...Option) *RedisLock {
r := &RedisLock{
key: key,
}
for _, option := range options {
option(r)
}
return r
}
Thanks for your suggestion!
Any benchmark to talk about the performance?
Thanks for your suggestion!
Any benchmark to talk about the performance?
Because the generation of random numbers will consume a certain amount of CPU, I am looking forward to more flexible input parameters. This brings two benefits: one is that it can reduce CPU consumption, and the other is that I need to specify the owner myself in some business scenarios. Such a change is also compatible with the old version, if the owner is not passed in, then generate a random number
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.