Skip to content

Commit 5980f54

Browse files
author
hero
committed
修改加锁的方式
1 parent 779c3f0 commit 5980f54

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

redis/lock/lock.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ import (
55
"time"
66
)
77

8-
9-
108
type RedisLock struct {
119
conn *redis.Client
1210
timeout time.Duration
1311
key string
1412
val string
1513
}
1614

17-
func NewRedisLock(conn *redis.Client, key, val string,timeout time.Duration) *RedisLock {
15+
func NewRedisLock(conn *redis.Client, key, val string, timeout time.Duration) *RedisLock {
1816
return &RedisLock{conn: conn, timeout: timeout, key: key, val: val}
1917
}
2018

2119
//return true ===> Get the lock successfully
2220
func (lock *RedisLock) TryLock() (bool, error) {
21+
//lock.conn.Do("SET",lock.key,lock.val,"EX",int(lock.timeout), "NX").Result()
2322
return lock.conn.SetNX(lock.key, lock.val, lock.timeout).Result()
2423
}
2524

0 commit comments

Comments
 (0)