Wednesday, July 10, 2024

Redis connection in node js

 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) { if (options.error && options.error.code === 'ECONNREFUSED') { // End reconnecting on a specific error and flush all commands with a individual error console.error('The server refused the connection'); return new Error('The server refused the connection'); } if (options.total_retry_time > 1000 * 60 * 60) { // End reconnecting after a specific timeout and flush all commands with a individual error console.error('Retry time exhausted'); return new Error('Retry time exhausted'); } if (options.attempt > 10) { // End reconnecting with built in error console.error('Too many retry attempts'); return undefined; } // Reconnect after a specific time return Math.min(options.attempt * 100, 3000); } }); client.on('connect', function() { console.log('Redis client connected'); }); client.on('error', function (err) { console.error('Something went wrong ' + err); }); export default client;

3 comments:

  1. Coverage on Buying Journal blends industry expertise and global perspectives, delivering articles that provide clarity, relevant insights, and practical strategies to understand and act on emerging trends.

    ReplyDelete
  2. Coverage on Greece Report blends local and regional perspectives, delivering articles that provide clarity, relevant insights, and thoughtful reporting on the key developments shaping Greece today.

    ReplyDelete
  3. With a focus on technology, AI, crypto, and fashion, Follower Magazine equips readers with timely updates, expert commentary, and engaging analysis to understand the digital world and global stories shaping our future.

    ReplyDelete

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