-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apollo-server-cache-redis: follow-up to #5034
Add docs and changelog. As part of doing this, realize that the implementation in #5034 makes it annoying to inject a cluster client, so switch the new API to decide about get vs mget based on which kind of client is passed to the base class.
- Loading branch information
Showing
8 changed files
with
151 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
packages/apollo-server-cache-redis/src/__tests__/BaseRedisCache.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
jest.mock('ioredis'); | ||
|
||
import { BaseRedisCache, RedisClient } from '../index'; | ||
import { | ||
testKeyValueCache_Basics, | ||
testKeyValueCache_Expiration, | ||
} from '../../../apollo-server-caching/src/__tests__/testsuite'; | ||
|
||
|
||
describe('BaseRedisCacheTest', () => { | ||
const store: { [key: string]: string } = {}; | ||
const timeouts: NodeJS.Timer[] = []; | ||
afterAll(() => { | ||
timeouts.forEach((t) => clearTimeout(t)); | ||
}); | ||
const testRedisClient: RedisClient = { | ||
set: jest.fn((key: string, value: string, option?: string, ttl?: number) => { | ||
store[key] = value; | ||
option === 'EX' && ttl && setTimeout(() => delete store[key], ttl * 1000); | ||
return Promise.resolve(); | ||
}), | ||
mget: jest.fn((...keys) => Promise.resolve(keys.map((key: string) => store[key]))), | ||
set: jest.fn( | ||
(key: string, value: string, option?: string, ttl?: number) => { | ||
store[key] = value; | ||
if (option === 'EX' && ttl) { | ||
timeouts.push(setTimeout(() => delete store[key], ttl * 1000)); | ||
} | ||
return Promise.resolve(); | ||
}, | ||
), | ||
mget: jest.fn((...keys) => | ||
Promise.resolve(keys.map((key: string) => store[key])), | ||
), | ||
flushdb: jest.fn(() => Promise.resolve()), | ||
del: jest.fn((key: string) => { | ||
const keysDeleted = store.hasOwnProperty(key) ? 1 : 0; | ||
delete store[key]; | ||
return Promise.resolve(keysDeleted); | ||
}), | ||
quit: jest.fn(() => Promise.resolve()), | ||
} | ||
}; | ||
|
||
const cache = new BaseRedisCache(testRedisClient); | ||
const cache = new BaseRedisCache({ client: testRedisClient }); | ||
testKeyValueCache_Basics(cache); | ||
testKeyValueCache_Expiration(cache); | ||
}); |