Files
Job-Info/Mode6Test/backend/cache-api.cjs
T
aewing 42ff3e8f33
Build & Deploy / Test & Lint (push) Has been cancelled
Build & Deploy / Security Scan (push) Has been cancelled
Code Quality / Code Quality Checks (push) Has been cancelled
Code Quality / Dependency Vulnerabilities (push) Has been cancelled
Code Quality / Performance Testing (push) Has been cancelled
Build & Deploy / Build Docker Images (push) Has been cancelled
Build & Deploy / Deploy to Kubernetes (push) Has been cancelled
Add Mode6Test: copy of Mode5Test running on port 3000
2026-01-20 13:43:29 +00:00

30 lines
875 B
JavaScript

// Simple Express API to serve all Redis/Valkey cache keys and values as JSON (CommonJS)
const express = require('express');
const Redis = require('ioredis');
const app = express();
const redis = new Redis({
host: process.env.REDIS_HOST || '127.0.0.1',
port: Number(process.env.REDIS_PORT || 6379),
password: process.env.REDIS_PASSWORD,
});
app.get('/api/cache', async (req, res) => {
try {
const keys = await redis.keys('*');
const result = [];
for (const key of keys) {
let value = await redis.get(key);
try { value = JSON.parse(value); } catch {}
result.push({ key, value });
}
res.json(result);
} catch (err) {
res.status(500).json({ error: err.message });
}
});
const port = process.env.CACHE_API_PORT || 3006;
app.listen(port, () => {
console.log(`Cache API running on http://localhost:${port}/api/cache`);
});