Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class buildRedisStoreWithConfig implements RedisStore {
return await this.redisCache.multi().set(key, updateFunction(await this.get(key))).get(key).exec();
}

public async incrBy(key: string, incrementBy: number): Promise<number> {
public async incrBy(key: string, incrementBy: number, ttl?: Milliseconds): Promise<number> {
const ttlValue = this.getTtl(ttl);
await this.redisCache.set(key, 0, {PX: ttlValue, NX: true});
return await this.redisCache.incrBy(key, incrementBy);
}

Expand Down
6 changes: 3 additions & 3 deletions test/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ describe('Redis Store', () => {

it('should increment a value', async () => {
const key = 'testKey';
const value = 1;

await redisClient.set(key, value);
const numberIncrBy = await redisClient.incrBy(key, 1);
const numberIncrBy = await redisClient.incrBy(key, 2);

const retrievedValue = await redisClient.get(key);
const ttl = await redisClient.ttl(key);
expect(ttl).to.not.equal(-1);
expect(numberIncrBy).toEqual(2);
expect(retrievedValue).toEqual(2);
});
Expand Down