29 lines
773 B
TypeScript
29 lines
773 B
TypeScript
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),
|
|
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;
|
|
},
|
|
};
|
|
});
|