chore: redislock use stringx.randn replace randomStr func (#1220)

This commit is contained in:
an
2021-11-10 21:14:21 +08:00
committed by GitHub
parent d3bfa16813
commit 3a510a9138
2 changed files with 5 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package redis
import (
"github.com/tal-tech/go-zero/core/stringx"
"math/rand"
"strconv"
"sync/atomic"
@@ -45,7 +46,7 @@ func NewRedisLock(store *Redis, key string) *RedisLock {
return &RedisLock{
store: store,
key: key,
id: randomStr(randomLen),
id: stringx.Randn(randomLen),
}
}
@@ -92,11 +93,3 @@ func (rl *RedisLock) Release() (bool, error) {
func (rl *RedisLock) SetExpire(seconds int) {
atomic.StoreUint32(&rl.seconds, uint32(seconds))
}
func randomStr(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}