Spaces:
Running
Running
debug: check Redis key type before reading, handle hash type
Browse files- health-server.js +16 -4
health-server.js
CHANGED
|
@@ -1956,15 +1956,27 @@ const server = http.createServer((req, res) => {
|
|
| 1956 |
if (!keys || keys.startsWith("(")) return ` ${pattern}: (none)\n`;
|
| 1957 |
let out = ` ${pattern} keys found:\n`;
|
| 1958 |
for (const key of keys.split("\n").filter(Boolean).slice(0, 5)) {
|
| 1959 |
-
const
|
| 1960 |
-
const ttl
|
| 1961 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1962 |
const colonIdx = val.indexOf(":");
|
| 1963 |
const token = colonIdx > 0 ? val.slice(0, colonIdx) : "";
|
| 1964 |
const secret = colonIdx > 0 ? val.slice(colonIdx + 1) : "";
|
| 1965 |
const extraColons = (val.match(/:/g) || []).length - 1;
|
| 1966 |
const note = colonIdx < 0 ? "⚠ NO COLON" : extraColons > 0 ? `⚠ ${extraColons} extra colon(s)` : secret.length < 30 ? "⚠ secret short" : "✓ ok";
|
| 1967 |
-
out += ` ${key} [TTL=${ttl}s]\n token: ${token.slice(0,12)}... (len=${token.length})\n secret: ${secret.slice(0,12)}... (len=${secret.length})\n note: ${note}\n`;
|
| 1968 |
}
|
| 1969 |
return out;
|
| 1970 |
};
|
|
|
|
| 1956 |
if (!keys || keys.startsWith("(")) return ` ${pattern}: (none)\n`;
|
| 1957 |
let out = ` ${pattern} keys found:\n`;
|
| 1958 |
for (const key of keys.split("\n").filter(Boolean).slice(0, 5)) {
|
| 1959 |
+
const type = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} type "${key}"`);
|
| 1960 |
+
const ttl = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} ttl "${key}" 2>/dev/null`);
|
| 1961 |
+
let val;
|
| 1962 |
+
if (type === "hash") {
|
| 1963 |
+
val = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} hgetall "${key}" 2>/dev/null`);
|
| 1964 |
+
} else if (type === "string") {
|
| 1965 |
+
val = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} get "${key}" 2>/dev/null`);
|
| 1966 |
+
} else {
|
| 1967 |
+
out += ` ${key} [type=${type} TTL=${ttl}]: (unhandled type)\n`; continue;
|
| 1968 |
+
}
|
| 1969 |
+
if (!val) { out += ` ${key} [type=${type} TTL=${ttl}]: VALUE IS EMPTY STRING\n`; continue; }
|
| 1970 |
+
if (type === "hash") {
|
| 1971 |
+
out += ` ${key} [type=hash TTL=${ttl}]:\n ${val.replace(/\n/g, "\n ").slice(0,300)}\n`;
|
| 1972 |
+
continue;
|
| 1973 |
+
}
|
| 1974 |
const colonIdx = val.indexOf(":");
|
| 1975 |
const token = colonIdx > 0 ? val.slice(0, colonIdx) : "";
|
| 1976 |
const secret = colonIdx > 0 ? val.slice(colonIdx + 1) : "";
|
| 1977 |
const extraColons = (val.match(/:/g) || []).length - 1;
|
| 1978 |
const note = colonIdx < 0 ? "⚠ NO COLON" : extraColons > 0 ? `⚠ ${extraColons} extra colon(s)` : secret.length < 30 ? "⚠ secret short" : "✓ ok";
|
| 1979 |
+
out += ` ${key} [type=string TTL=${ttl}s]\n token: ${token.slice(0,12)}... (len=${token.length})\n secret: ${secret.slice(0,12)}... (len=${secret.length})\n note: ${note}\n`;
|
| 1980 |
}
|
| 1981 |
return out;
|
| 1982 |
};
|