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
21 changes: 21 additions & 0 deletions src/FastCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/FastCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface SortedSetOperations {
add(score: number, value: string): Promise<void>;
addAll(entries: Array<{ score: number; value: string }>): Promise<void>;
remove(...values: Array<string>): Promise<void>;
zincrBy(value: string, increment: number): Promise<number>;
range({
start,
stop,
Expand Down Expand Up @@ -237,6 +238,10 @@ export class FastCache {
remove: async (...values: Array<string>): Promise<void> => {
await this.client.zrem(key, ...values);
},
zincrBy: async (value: string, increment: number): Promise<number> => {
const result = await this.client.zincrby(key, increment, value);
return parseFloat(result);
},
range: async ({
start,
stop,
Expand Down