Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
redis-client-sdk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
go
redis-client-sdk
Commits
293be8a5
Commit
293be8a5
authored
Oct 24, 2022
by
yemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
2c7ba0f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
RedisClient.go
redis/RedisClient.go
+19
-0
No files found.
redis/RedisClient.go
View file @
293be8a5
...
...
@@ -148,6 +148,25 @@ func Unlock(k, uniqueValue string) bool {
return
false
}
// LockWait 抢锁,在规定的时间内直到抢锁成功或者超时失败。抢到锁返回true,否则false
// k 必须
// uniqueValue 必须
// timeoutSecond 锁自动释放时间,必须
// lockTimeoutSecond 抢锁超时时间,默认1分钟
func
LockWait
(
k
,
uniqueValue
string
,
timeoutSecond
int
,
lockTimeoutSecond
int
)
bool
{
if
lockTimeoutSecond
==
0
{
lockTimeoutSecond
=
60
}
loopCount
:=
lockTimeoutSecond
*
10
for
i
:=
0
;
i
<
loopCount
;
i
++
{
if
Lock
(
k
,
uniqueValue
,
timeoutSecond
)
{
return
true
}
time
.
Sleep
(
time
.
Duration
(
100
)
*
time
.
Millisecond
)
//100ms
}
return
false
}
// Hset 向一张hash表中放入数据,如果不存在将创建
func
Hset
(
k
,
i
,
v
string
,
timeoutSecond
int
)
error
{
e
:=
getDb
()
.
HSet
(
k
,
i
,
v
)
.
Err
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment