feat: keys with scan backend
This commit is contained in:
parent
622ddb3f59
commit
7780efa239
|
@ -6,3 +6,27 @@ const {
|
|||
} = process.env;
|
||||
|
||||
export default () => redis.createClient(REDIS_PORT, REDIS_HOST);
|
||||
|
||||
const safeKeys = async (result, client, pattern, caret) => {
|
||||
do {
|
||||
// eslint-disable-next-line no-await-in-loop, no-loop-func
|
||||
await new Promise((resolve, reject) => {
|
||||
client.scan(caret, 'MATCH', pattern, (error, r) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
caret = parseInt(r[0], 10);
|
||||
result.push(...r[1]);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} while (0 !== caret);
|
||||
};
|
||||
|
||||
export const keys = async (client, pattern) => {
|
||||
const result = [];
|
||||
await safeKeys(result, client, pattern, 0);
|
||||
return result;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user