Skip to content

Commit

Permalink
use pExpire instead
Browse files Browse the repository at this point in the history
  • Loading branch information
MARCROCK22 committed Sep 18, 2024
1 parent ed77123 commit 226f62d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/redis-adapter/src/expirableAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ExpirableRedisAdapter extends RedisAdapter {
const cacheType = key.split('.')[0] as keyof ExpirableRedisAdapterOptions;
const expire = this.options[cacheType]?.expire ?? this.options.default.expire!;
if (expire > 0) {
promises.push(this.client.set(`${this.buildKey(key)}.uset.${value}`, 's', { EX: expire }));
promises.push(this.client.set(`${this.buildKey(key)}.uset.${value}`, 's', { PX: expire }));
} else {
promises.push(this.client.set(`${this.buildKey(key)}.uset.${value}`, 's'));
}
Expand Down Expand Up @@ -138,7 +138,7 @@ export class ExpirableRedisAdapter extends RedisAdapter {

const expire = this.options[cacheType]?.expire ?? this.options.default.expire!;
if (expire > 0) {
promises.push(this.client.expire(this.buildKey(id), expire));
promises.push(this.client.pExpire(this.buildKey(id), expire));
}

await Promise.all(promises);
Expand Down Expand Up @@ -167,7 +167,7 @@ export class ExpirableRedisAdapter extends RedisAdapter {
const cacheType = id.split('.')[0] as keyof ExpirableRedisAdapterOptions;
const expire = this.options[cacheType]?.expire ?? this.options.default.expire!;
if (expire > 0) {
promises.push(this.client.expire(this.buildKey(id), expire));
promises.push(this.client.pExpire(this.buildKey(id), expire));
}

await Promise.all(promises);
Expand Down
15 changes: 11 additions & 4 deletions packages/redis-adapter/test/expirableadapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ describe('ExpirableRedisAdapter', async () => {
['key2', { value: 'value2' }],
];

const adapter = new ExpirableRedisAdapter({
redisOptions: {},
namespace: 'ex_custom_namespace',
});
const adapter = new ExpirableRedisAdapter(
{
redisOptions: {},
namespace: 'ex_custom_namespace',
},
{
default: {
expire: 2e3,
},
},
);

await adapter.start();

Expand Down
2 changes: 1 addition & 1 deletion packages/redis-adapter/test/expirablecache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Test Adapter cache', async t => {
},
{
default: {
expire: 2,
expire: 2e3,
},
},
);
Expand Down

0 comments on commit 226f62d

Please sign in to comment.