2022-06-06 17:38:20 +00:00
|
|
|
import RedisDocumentStore from 'src/lib/document-stores/redis'
|
2022-06-07 08:50:51 +00:00
|
|
|
import { StoreNames } from 'src/types/store-names'
|
2022-05-27 13:04:54 +00:00
|
|
|
|
|
|
|
describe('Redis document store', () => {
|
|
|
|
let store: RedisDocumentStore
|
|
|
|
/* reconnect to redis on each test */
|
|
|
|
afterEach(() => {
|
|
|
|
if (store) {
|
|
|
|
store.client?.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('set', () => {
|
|
|
|
it('should be able to set a key and have an expiration set', async () => {
|
|
|
|
store = new RedisDocumentStore({
|
|
|
|
expire: 10,
|
2022-06-07 08:50:51 +00:00
|
|
|
type: StoreNames.redis
|
2022-05-27 13:04:54 +00:00
|
|
|
})
|
|
|
|
return store.set('hello1', 'world', async () => {
|
|
|
|
const res = await store.client?.ttl('hello1')
|
|
|
|
expect(res).toBeGreaterThan(1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not set an expiration when told not to', async () => {
|
|
|
|
store = new RedisDocumentStore({
|
|
|
|
expire: 10,
|
2022-06-07 08:50:51 +00:00
|
|
|
type: StoreNames.redis
|
2022-05-27 13:04:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
store.set(
|
|
|
|
'hello2',
|
|
|
|
'world',
|
|
|
|
async () => {
|
|
|
|
const res = await store.client?.ttl('hello2')
|
|
|
|
expect(res).toEqual(-1)
|
|
|
|
},
|
2022-06-07 08:50:51 +00:00
|
|
|
true
|
2022-05-27 13:04:54 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not set an expiration when expiration is off', async () => {
|
|
|
|
store = new RedisDocumentStore({
|
2022-06-07 08:50:51 +00:00
|
|
|
type: StoreNames.redis
|
2022-05-27 13:04:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
store.set('hello3', 'world', async () => {
|
|
|
|
const res = await store.client?.ttl('hello3')
|
|
|
|
expect(res).toEqual(-1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|