Skip to content

Commit

Permalink
feat: adds support for unlink cmd (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: eaddingtonwhite <[email protected]>
  • Loading branch information
eaddingtonwhite and eaddingtonwhite authored Apr 24, 2024
1 parent a8400a8 commit e1b0c8c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/momento-redis-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ export interface MomentoIORedis {
flushdb(async: 'ASYNC'): Promise<'OK'>;
flushdb(sync: 'SYNC'): Promise<'OK'>;

unlink(...args: [...keys: RedisKey[]]): Promise<number>;

quit(): Promise<'OK'>;
}

Expand Down Expand Up @@ -805,6 +807,11 @@ export class MomentoRedisAdapter
return 0;
}

async unlink(...args: [...keys: RedisKey[]]): Promise<number> {
await this.del(...args);
return args.length;
}

async flushdb(): Promise<'OK'> {
const rsp = await this.momentoClient.flushCache(this.cacheName);
if (rsp instanceof CacheFlush.Success) {
Expand Down
27 changes: 27 additions & 0 deletions test/get-set-delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,30 @@ describe('setex', () => {
expect(getResult2).toBeNull();
});
});

describe('unlink', () => {
it('happy path set get update unlink test', async () => {
const key = v4();
const value1 = v4();
const value2 = v4();
// Set initial key value
await client.set(key, value1);

// Get value
let result = await client.get(key);
expect(result).toEqual(value1);

// Update value
await client.set(key, value2);

// Read updated value
result = await client.get(key);
expect(result).toEqual(value2);
// Unlink key aka "Delete"
await client.unlink(key);

// Should get null back now
result = await client.get(key);
expect(result).toBeNull();
});
});

0 comments on commit e1b0c8c

Please sign in to comment.