Commit 003f2f64 authored by nanahira's avatar nanahira

fix redlock thing

parent cbfa7c84
......@@ -21,7 +21,7 @@ export class RedisDriver extends BaseDriver {
const redis = await this.createRedisClient();
return {
redis,
redlock: new Redlock([redis], this.options.lock),
// redlock: new Redlock([redis], this.options.lock),
};
},
destroy: async ({ redis }) => {
......@@ -85,13 +85,13 @@ export class RedisDriver extends BaseDriver {
await this.pool.use((r) => r.redis.del(keys));
}
override lock<R>(keys: string[], cb: () => Promise<R>): Promise<R> {
return this.pool.use((r) =>
r.redlock.using(
keys.map((key) => `${this.options.lock?.prefix || '_lock'}:${key}`),
this.options.lock?.duration || 5000,
cb,
),
override async lock<R>(keys: string[], cb: () => Promise<R>): Promise<R> {
const redis = await this.createRedisClient();
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,
);
}
......
......@@ -97,7 +97,9 @@ describe('Aragami.', () => {
},
(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 () => {
......
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