const express = require('express');
const redis = require('redis'); const { promisify } = require('util'); const app = express(); const PORT = 3000; // Replace with your desired port // Create a Redis client with a connection timeout (in milliseconds) const client = redis.createClient({ host: '127.0.0.1', // Replace with your Redis server host port: 6379, // Replace with your Redis server port if different from default connect_timeout: 10000 // 10 seconds timeout }); // Promisify the `flushdb` method const flushdbAsync = promisify(client.flushdb).bind(client); // Function to flush the Redis database async function flushRedisDatabase() { try { const result = await flushdbAsync(); return { message: 'Database flushed successfully', result }; } catch (err) { console.error('Error flushing database:', err); throw err; } } // REST endpoint to flush the Redis database app.post('/flushdb', async (req, res) => { try { const response = await flushRedisDatabase(); res.status(200).json(response); } catch (err) { res.status(500).json({ error: 'Error flushing database', details: err.message }); } }); // Start the Express server app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); // Additional Redis client event handlers for better debugging client.on('connect', () => { console.log('Connected to Redis'); }); client.on('error', (err) => { console.error('Redis error:', err); }); client.on('ready', () => { console.log('Redis client ready'); }); client.on('reconnecting', () => { console.log('Reconnecting to Redis...'); }); client.on('end', () => { console.log('Redis connection closed'); });
Articles on Denmark Report provide comprehensive coverage of political affairs, economic trends, and international news, offering readers actionable insights and reliable information on Denmark’s ongoing transformations.
ReplyDeleteArticles on Croatia Wire provide comprehensive coverage of political events, social developments, and news insights, offering readers actionable knowledge and reliable perspectives on Croatia’s ongoing transformations.
ReplyDeleteInsightful articles on Cyprus Magazine offer readers perspectives on technological breakthroughs, cultural highlights, educational programs, and eco-friendly trends, helping audiences explore and understand Cyprus’s evolving landscape.
ReplyDelete