runtipi/__mocks__/redis.ts

30 lines
773 B
TypeScript
Raw Permalink Normal View History

const values = new Map();
const expirations = new Map();
export const createClient = jest.fn(() => {
return {
isOpen: true,
connect: jest.fn(),
set: (key: string, value: string, exp: number) => {
values.set(key, value);
expirations.set(key, exp);
},
get: (key: string) => values.get(key),
quit: jest.fn(),
del: (key: string) => values.delete(key),
ttl: (key: string) => expirations.get(key),
2023-04-13 19:54:26 +00:00
on: jest.fn(),
keys: (key: string) => {
const keyprefix = key.substring(0, key.length - 1);
const keys = [];
// eslint-disable-next-line no-restricted-syntax
for (const [k] of values) {
if (k.startsWith(keyprefix)) {
keys.push(k);
}
}
return keys;
},
};
});