Commit 003f2f64 authored by nanahira's avatar nanahira

fix redlock thing

parent cbfa7c84
...@@ -21,7 +21,7 @@ export class RedisDriver extends BaseDriver { ...@@ -21,7 +21,7 @@ export class RedisDriver extends BaseDriver {
const redis = await this.createRedisClient(); const redis = await this.createRedisClient();
return { return {
redis, redis,
redlock: new Redlock([redis], this.options.lock), // redlock: new Redlock([redis], this.options.lock),
}; };
}, },
destroy: async ({ redis }) => { destroy: async ({ redis }) => {
...@@ -85,13 +85,13 @@ export class RedisDriver extends BaseDriver { ...@@ -85,13 +85,13 @@ export class RedisDriver extends BaseDriver {
await this.pool.use((r) => r.redis.del(keys)); await this.pool.use((r) => r.redis.del(keys));
} }
override lock<R>(keys: string[], cb: () => Promise<R>): Promise<R> { override async lock<R>(keys: string[], cb: () => Promise<R>): Promise<R> {
return this.pool.use((r) => const redis = await this.createRedisClient();
r.redlock.using( const redlock = new Redlock([redis], this.options.lock);
keys.map((key) => `${this.options.lock?.prefix || '_lock'}:${key}`), return redlock.using(
this.options.lock?.duration || 5000, keys.map((key) => `${this.options.lock?.prefix || '_lock'}:${key}`),
cb, this.options.lock?.duration || 5000,
), cb,
); );
} }
......
...@@ -97,7 +97,9 @@ describe('Aragami.', () => { ...@@ -97,7 +97,9 @@ describe('Aragami.', () => {
}, },
(foo, bar) => [foo, bar], (foo, bar) => [foo, bar],
); );
await expect(fun('foo', 'bar')).resolves.toEqual('foo.bar'); await expect(
Promise.all([fun('foo', 'bar'), fun('foo', 'baz')]),
).resolves.toStrictEqual(['foo.bar', 'foo.baz']);
}); });
it('should wrap class', async () => { it('should wrap class', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment