Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
A
Aragami
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Aragami
Commits
932273f2
Commit
932273f2
authored
Dec 14, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support stacked lock
parent
00e990df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
src/def.ts
src/def.ts
+1
-1
src/drivers/redis.ts
src/drivers/redis.ts
+17
-8
No files found.
src/def.ts
View file @
932273f2
...
...
@@ -3,7 +3,7 @@ import { Settings } from '@nanahira/redlock';
export
type
RedisDriverOptions
=
RedisOptions
&
{
uri
?:
string
;
lock
?:
Settings
&
{
duration
?:
number
;
prefix
?:
string
};
lock
?:
Settings
&
{
duration
?:
number
;
prefix
?:
string
;
stacked
?:
boolean
};
queueKey
?:
string
;
};
...
...
src/drivers/redis.ts
View file @
932273f2
...
...
@@ -3,6 +3,7 @@ import Redis from 'ioredis';
import
Redlock
from
'
@nanahira/redlock
'
;
import
{
Awaitable
,
RedisDriverOptions
}
from
'
../def
'
;
import
{
createPool
}
from
'
generic-pool
'
;
import
BetterLock
from
'
better-lock
'
;
export
class
RedisDriver
extends
BaseDriver
{
async
createRedisClient
()
{
...
...
@@ -94,15 +95,23 @@ export class RedisDriver extends BaseDriver {
await
this
.
pool
.
use
((
r
)
=>
r
.
redis
.
del
(
keys
));
}
private
betterLock
=
new
BetterLock
();
override
async
lock
<
R
>
(
keys
:
string
[],
cb
:
()
=>
Promise
<
R
>
):
Promise
<
R
>
{
return
this
.
useTempRedisClient
(
async
(
redis
)
=>
{
const
redlock
=
new
Redlock
([
redis
],
this
.
options
.
lock
);
return
redlock
.
using
(
keys
.
map
((
key
)
=>
`
${
this
.
options
.
lock
?.
prefix
||
'
_lock
'
}:
$
{
key
}
`
),
this
.
options
.
lock
?.
duration
||
5000
,
cb
,
);
});
const
run
=
()
=>
this
.
useTempRedisClient
(
async
(
redis
)
=>
{
const
redlock
=
new
Redlock
([
redis
],
this
.
options
.
lock
);
return
redlock
.
using
(
keys
.
map
((
key
)
=>
`
${
this
.
options
.
lock
?.
prefix
||
'
_lock
'
}:
$
{
key
}
`
),
this
.
options
.
lock
?.
duration
||
5000
,
cb
,
);
});
if
(
this
.
options
?.
lock
?.
stacked
)
{
return
this
.
betterLock
.
acquire
(
keys
,
run
);
}
else
{
return
run
();
}
}
override
async
isFree
(
keys
:
string
[]):
Promise
<
boolean
>
{
...
...
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