diff --git a/src/FastCache.spec.ts b/src/FastCache.spec.ts index 8f957c3..d93d392 100644 --- a/src/FastCache.spec.ts +++ b/src/FastCache.spec.ts @@ -431,6 +431,27 @@ describe('FastCache', () => { expect(values).toHaveLength(0); }); }); + + describe('zincrBy', () => { + test('값의 score를 증가시키면 증가된 score가 반환된다', async () => { + const sortedSet = cache.sortedSet('hello'); + + await sortedSet.add(100, 'foo'); + const newScore1 = await sortedSet.zincrBy('foo', 50); + expect(newScore1).toBe(150); + const newScore2 = await sortedSet.zincrBy('foo', 25); + expect(newScore2).toBe(175); + }); + + test('새로운 값을 추가할 때도 정상 동작하는지 확인', async () => { + const sortedSet = cache.sortedSet('hello'); + await sortedSet.zincrBy('foo', 10); + + const score = await sortedSet.score('foo'); + + expect(score).toBe(10); + }); + }); }); describe('withCache', () => { diff --git a/src/FastCache.ts b/src/FastCache.ts index f973215..2955f5e 100644 --- a/src/FastCache.ts +++ b/src/FastCache.ts @@ -47,6 +47,7 @@ export interface SortedSetOperations { add(score: number, value: string): Promise; addAll(entries: Array<{ score: number; value: string }>): Promise; remove(...values: Array): Promise; + zincrBy(value: string, increment: number): Promise; range({ start, stop, @@ -237,6 +238,10 @@ export class FastCache { remove: async (...values: Array): Promise => { await this.client.zrem(key, ...values); }, + zincrBy: async (value: string, increment: number): Promise => { + const result = await this.client.zincrby(key, increment, value); + return parseFloat(result); + }, range: async ({ start, stop,