Skip to content

Commit

Permalink
fix: give redlock enough time for locking (chrisleekr#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
habibalkhabbaz authored Oct 7, 2022
1 parent ff40fee commit 2a592e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions app/helpers/__tests__/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 1000);
});

it('does not trigger setex', () => {
Expand All @@ -100,7 +100,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 1000);
});

it('triggers setex', () => {
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 1000);
});

it('triggers get', () => {
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key', 1000);
});

it('triggers del', () => {
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 1000);
});

it('triggers set', () => {
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 1000);
});

it('triggers setex', () => {
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 1000);
});

it('triggers get', () => {
Expand Down Expand Up @@ -566,7 +566,7 @@ describe('cache', () => {
});

it('triggers lock', () => {
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 500);
expect(mockLock).toHaveBeenCalledWith('redlock:my-key:my-field', 1000);
});

it('triggers del', () => {
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const keys = async pattern => redis.keys(pattern);
* @param {*} ttl seconds
*/
const set = async (key, value, ttl = undefined) => {
const lock = await redlock.lock(`redlock:${key}`, 500);
const lock = await redlock.lock(`redlock:${key}`, 1000);

let result;
if (ttl) {
Expand All @@ -63,7 +63,7 @@ const set = async (key, value, ttl = undefined) => {
* @param {*} key
*/
const get = async key => {
const lock = await redlock.lock(`redlock:${key}`, 500);
const lock = await redlock.lock(`redlock:${key}`, 1000);
const result = await redis.get(key);
await lock.unlock();

Expand Down Expand Up @@ -93,7 +93,7 @@ const getWithTTL = async key => redis.multi().ttl(key).get(key).exec();
* @param {*} key
*/
const del = async key => {
const lock = await redlock.lock(`redlock:${key}`, 500);
const lock = await redlock.lock(`redlock:${key}`, 1000);
const result = await redis.del(key);
await lock.unlock();
return result;
Expand Down

0 comments on commit 2a592e1

Please sign in to comment.