From e1b0c8cdc7b41d3cc4184f272b00993d73749dbd Mon Sep 17 00:00:00 2001 From: eaddingtonwhite <5491827+eaddingtonwhite@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:20:10 -0700 Subject: [PATCH] feat: adds support for unlink cmd (#32) Co-authored-by: eaddingtonwhite <5491827+ellery44@users.noreply.github.com> --- src/momento-redis-adapter.ts | 7 +++++++ test/get-set-delete.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/momento-redis-adapter.ts b/src/momento-redis-adapter.ts index 2417082..ff4813d 100644 --- a/src/momento-redis-adapter.ts +++ b/src/momento-redis-adapter.ts @@ -184,6 +184,8 @@ export interface MomentoIORedis { flushdb(async: 'ASYNC'): Promise<'OK'>; flushdb(sync: 'SYNC'): Promise<'OK'>; + unlink(...args: [...keys: RedisKey[]]): Promise; + quit(): Promise<'OK'>; } @@ -805,6 +807,11 @@ export class MomentoRedisAdapter return 0; } + async unlink(...args: [...keys: RedisKey[]]): Promise { + await this.del(...args); + return args.length; + } + async flushdb(): Promise<'OK'> { const rsp = await this.momentoClient.flushCache(this.cacheName); if (rsp instanceof CacheFlush.Success) { diff --git a/test/get-set-delete.test.ts b/test/get-set-delete.test.ts index 010f374..bc1e23f 100644 --- a/test/get-set-delete.test.ts +++ b/test/get-set-delete.test.ts @@ -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(); + }); +});