Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
redlock
Overview
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
刘旋尧
redlock
Commits
1fa42ede
Commit
1fa42ede
authored
Aug 22, 2018
by
刘旋尧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8a049003
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
Lock.php
src/Lock.php
+16
-16
No files found.
src/Lock.php
View file @
1fa42ede
...
@@ -6,29 +6,23 @@ use Predis;
...
@@ -6,29 +6,23 @@ use Predis;
class
Lock
class
Lock
{
{
public
$
addr
=
''
;
public
$
timeout
=
200
;
private
$client
;
private
$client
;
private
$randomStr
;
private
$randomStr
;
private
$timeout
=
200
;
const
LOCK_PREFIX
=
"LOCK_"
;
public
function
__construct
(
$addr
=
''
)
const
LOCK_PREFIX
=
"LOCK_"
;
{
if
(
$addr
)
{
$this
->
addr
=
$addr
;
}
if
(
$this
->
addr
)
{
$this
->
init
();
}
}
public
function
init
(
)
public
function
__construct
(
$addr
)
{
{
parent
::
init
();
$this
->
client
=
new
Predis\Client
(
$addr
);
$this
->
client
=
new
Predis\Client
(
$this
->
addr
);
$this
->
randomStr
=
$this
->
randomStr
();
$this
->
randomStr
=
$this
->
randomStr
();
}
}
/**
* 加锁
*
* @param [type] $key
* @return boolean
*/
public
function
lock
(
$key
)
public
function
lock
(
$key
)
{
{
$rs
=
$this
->
client
->
set
(
self
::
LOCK_PREFIX
.
$key
,
$this
->
randomStr
,
'NX'
,
'PX'
,
$this
->
timeout
);
$rs
=
$this
->
client
->
set
(
self
::
LOCK_PREFIX
.
$key
,
$this
->
randomStr
,
'NX'
,
'PX'
,
$this
->
timeout
);
...
@@ -37,6 +31,12 @@ class Lock
...
@@ -37,6 +31,12 @@ class Lock
}
}
/**
* 解锁
*
* @param [type] $key
* @return void
*/
public
function
unLock
(
$key
)
public
function
unLock
(
$key
)
{
{
$val
=
$this
->
client
->
get
(
self
::
LOCK_PREFIX
.
$key
);
$val
=
$this
->
client
->
get
(
self
::
LOCK_PREFIX
.
$key
);
...
...
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