diff --git a/package.json b/package.json index c9ad113..7d3821c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "memoredis", - "version": "1.0.1", + "version": "1.0.2", "description": "Redis memoization library with good Typescript generics, locking, and argument-wide bulk invalidation", "main": "build/main/index.js", "typings": "build/main/index.d.ts", diff --git a/src/lib/memoizer.spec.ts b/src/lib/memoizer.spec.ts index e9595b9..7d6ed3b 100644 --- a/src/lib/memoizer.spec.ts +++ b/src/lib/memoizer.spec.ts @@ -175,3 +175,30 @@ describe('invalidation', () => { expect(mock).toHaveBeenCalledTimes(1); }); }); + +describe('prefixes', () => { + test('should keep keyspaces separate', async () => { + const a = createMemoizer({ prefix: 'a' }); + const b = createMemoizer({ prefix: 'b' }); + + const mock = jest.fn(); + + const memoizableFunction = async () => { + mock(); + return 4; + }; + + const aF = a.memoize(memoizableFunction, { + key: 'prefix-test' + }); + + const bF = b.memoize(memoizableFunction, { + key: 'prefix-test' + }); + + await aF({ a: 1 }); + await bF({ a: 1 }); + + expect(mock).toHaveBeenCalledTimes(2); + }); +}); diff --git a/src/lib/memoizer.ts b/src/lib/memoizer.ts index 2b9437a..b61908c 100644 --- a/src/lib/memoizer.ts +++ b/src/lib/memoizer.ts @@ -54,7 +54,7 @@ export const createMemoizer = (instanceOpts: MemoizerOpts) => { client.get(key, (err, reply) => err ? reject(err) - : resolve(reply === null ? (JSON.parse(reply) as T) : (reply as null)) + : resolve(reply !== null ? (JSON.parse(reply) as T) : (reply as null)) ) );