2023-08-28 19:44:53 +00:00
|
|
|
const values = new Map();
|
|
|
|
const expirations = new Map();
|
|
|
|
|
2022-12-26 03:52:48 +00:00
|
|
|
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(),
|
2023-04-07 20:32:14 +00:00
|
|
|
keys: (key: string) => {
|
2023-05-05 06:45:34 +00:00
|
|
|
const keyprefix = key.substring(0, key.length - 1);
|
2023-04-07 20:32:14 +00:00
|
|
|
const keys = [];
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
for (const [k] of values) {
|
2023-05-05 06:45:34 +00:00
|
|
|
if (k.startsWith(keyprefix)) {
|
2023-04-07 20:32:14 +00:00
|
|
|
keys.push(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
},
|
2022-12-26 03:52:48 +00:00
|
|
|
};
|
|
|
|
});
|