@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
69 lines • 1.6 kB
JavaScript
/**
* @module Cache
*/
import {} from "ioredis";
/**
* @internal
*/
function escapeRedisChars(value) {
const replacements = {
",": "\\,",
".": "\\.",
"<": "\\<",
">": "\\>",
"{": "\\{",
"}": "\\}",
"[": "\\[",
"]": "\\]",
'"': '\\"',
"'": "\\'",
":": "\\:",
";": "\\;",
"!": "\\!",
"@": "\\@",
"#": "\\#",
$: "\\$",
"%": "\\%",
"^": "\\^",
"&": "\\&",
"*": "\\*",
"(": "\\(",
")": "\\)",
"-": "\\-",
"+": "\\+",
"=": "\\=",
"~": "\\~",
};
return value.replace(/,|\.|<|>|\{|\}|\[|\]|"|'|:|;|!|@|#|\$|%|\^|&|\*|\(|\)|-|\+|=|~/g, (chunk) => {
const item = replacements[chunk];
if (item === undefined) {
throw new Error("Encounterd none existing field");
}
return item;
});
}
/**
* @internal
*/
export class ClearIterable {
client;
pattern;
constructor(client, pattern) {
this.client = client;
this.pattern = pattern;
this.pattern = `${escapeRedisChars(pattern)}*`;
}
async *[Symbol.asyncIterator]() {
let coursor = 0;
do {
const [_coursor, elements] = await this.client.scan(coursor, "MATCH", this.pattern);
if (elements.length === 0) {
return;
}
await this.client.del(elements);
coursor++;
yield undefined;
} while (coursor !== 0);
}
}
//# sourceMappingURL=utilities.js.map