Merged in fix/redis-shutdown-graceful (pull request #1969)
Fix/redis shutdown graceful * fix: shutdown redis gracefully when container restarts * throttle scans to redis to avoid overwhelming it Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -5,6 +5,7 @@ import { redis } from "@/services/redis";
|
||||
import { ModelValidationError } from "@/errors/ModelValidationError";
|
||||
import { loggerModule } from "@/utils/logger";
|
||||
import { truncate } from "@/utils/truncate";
|
||||
import { timeout } from "@/utils/timeout";
|
||||
|
||||
const MIN_LENGTH = 1;
|
||||
|
||||
@@ -92,10 +93,13 @@ function validateKey(key: string) {
|
||||
|
||||
if (parsedKey.length < MIN_LENGTH) {
|
||||
throw new ModelValidationError(
|
||||
"Key has to be atleast 1 character long"
|
||||
"Key has to be at least 1 character long"
|
||||
);
|
||||
}
|
||||
|
||||
if (parsedKey.includes("*")) {
|
||||
throw new ModelValidationError("Key cannot contain wildcards");
|
||||
}
|
||||
if (parsedKey.includes("*")) {
|
||||
throw new ModelValidationError("Key cannot contain wildcards");
|
||||
}
|
||||
@@ -115,6 +119,10 @@ async function deleteWithPattern(pattern: string) {
|
||||
"COUNT",
|
||||
5000
|
||||
);
|
||||
|
||||
// Throttle calls to Redis to avoid overwhelming it
|
||||
await timeout(50);
|
||||
|
||||
cursor = newCursor;
|
||||
keys.push(...foundKeys);
|
||||
} while (cursor !== "0");
|
||||
|
||||
Reference in New Issue
Block a user