-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache-manager - feat: adding in stores property (#981)
* cache-manager - feat: adding in stores property * adding in disconnect * adding in stores in readme * adding in iterator documentation * adding in TOC * updating modules
- Loading branch information
Showing
4 changed files
with
98 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Keyv} from 'keyv'; | ||
import {createKeyv} from '@keyv/redis'; | ||
import { | ||
describe, expect, it, | ||
} from 'vitest'; | ||
import {simpleFaker} from '@faker-js/faker'; | ||
import {createCache} from '../src/index.js'; | ||
|
||
describe('stores', () => { | ||
it('can get the keyv store', () => { | ||
const cache = createCache(); | ||
expect(cache.stores.length).toEqual(1); | ||
}); | ||
|
||
it('can see multiple stores', () => { | ||
const keyv = new Keyv(); | ||
const redis = createKeyv(); | ||
const cache = createCache({stores: [keyv, redis]}); | ||
expect(cache.stores.length).toEqual(2); | ||
expect(cache.stores[0]).toEqual(keyv); | ||
expect(cache.stores[1]).toEqual(redis); | ||
}); | ||
|
||
it('can get the keyv store and do iterator', async () => { | ||
const cache = createCache(); | ||
expect(cache.stores.length).toEqual(1); | ||
const keyName = simpleFaker.string.uuid(); | ||
const keyValue = simpleFaker.string.uuid(); | ||
await cache.set(keyName, keyValue); | ||
const keyv = cache.stores[0]; | ||
expect(keyv).toBeInstanceOf(Keyv); | ||
|
||
let returnValue; | ||
|
||
if (keyv?.iterator) { | ||
for await (const [key, value] of keyv.iterator({})) { | ||
if (key === keyName) { | ||
returnValue = value; | ||
} | ||
} | ||
} | ||
|
||
expect(returnValue).toEqual(keyValue); | ||
}); | ||
}); |