import redis from 'redis';
// Create a Redis client with retry strategy const client = redis.createClient({ host: 'localhost', // Replace with your Redis server host port: 6379, // Replace with your Redis server port retry_strategy: function (options) { // options.error contains the error object returned by the last attempt to connect if (options.error && options.error.code === 'ECONNREFUSED') { // If the connection was refused by the server, log the error and stop retrying console.error('The server refused the connection'); return new Error('The server refused the connection'); } // options.total_retry_time is the total time (in milliseconds) that the client has been trying to reconnect if (options.total_retry_time > 1000 * 60 * 60) { // If the total retry time exceeds 1 hour, log the error and stop retrying console.error('Retry time exhausted'); return new Error('Retry time exhausted'); } // options.attempt is the number of retry attempts so far if (options.attempt > 10) { // If the number of retry attempts exceeds 10, log the error and stop retrying console.error('Too many retry attempts'); return undefined; } // Reconnect after a specific time, which increases with each attempt // options.attempt * 100 gives a delay that increases by 100ms with each attempt // Math.min ensures the delay does not exceed 3000ms (3 seconds) return Math.min(options.attempt * 100, 3000); } }); // Event listener for successful connection client.on('connect', function() { console.log('Redis client connected'); }); // Event listener for errors client.on('error', function (err) { console.error('Something went wrong ' + err); }); export default client;
Subscribe to:
Post Comments (Atom)
Create a Digital Clock using HTML and JavaScript
Create a Digital Clock using HTML and JavaScript <! DOCTYPE html> < html > < head > ...
Followers
Search This Blog
Popular Posts
-
MG-CEIT Course Feedback Form Step1: Like below three pages for the updated course information ...
-
Question 1 Which framework is most commonly used for unit testing in Java? JUnit TestNG Mockito Selenium Answer: JUnit Question 2 I...
-
Software Development Tools Presentation From the moment you begin developing software, whether as a freelancer for a startup or wo...
-
max-request-journal-entries and no-request-journal in wiremock configuration In WireMock, the request journal is a built-in feature that ke...
-
import redis from 'redis'; // Create a Redis client with retry strategy const client = redis.createClient({ host: 'localhos...
-
const redis = require('redis'); const { promisify } = require('util'); // Create a Redis client with a connection timeout...
-
Use Request Dispatcher Servlet in creating simple Login Form We are going to create a Login Form Here. At the end of this section, y...
-
CDAC Certifications Courses List IT Applications Certificate Course in Business Computing Certificate Course in Global su...
-
कोरोना को जाने प्रश्न (1) :- क्या कोरोना वायरस को ख़त्म किया जा सकता है उत्तर:- नहीं! कोरोना वायर...
-
const express = require('express'); const redis = require('redis'); const { promisify } = require('util'); const ...
Covering technology, business, and climate developments with clarity, Finland Journal delivers well-researched articles and insightful analysis, providing readers with valuable updates and perspectives on innovations driving sustainable change in Finland and beyond.
ReplyDeleteArticles on Turkey Report combine expert commentary, clear reporting, and contextual analysis, giving readers meaningful perspectives on politics, economy, and regional affairs, while keeping them updated on Turkey’s current developments.
ReplyDeleteWith timely updates and professional analysis, Malta Journal provides readers comprehensive coverage of tech, business, culture, and global trends, offering clarity, inspiration, and understanding of Malta’s role in the digital world.
ReplyDelete