0

At the start of the server, I need to clean out my Redis memory. But every time a new cluster forms, it calls flushall and cleans out everything in memory. How do I run flushall only once from the very beginning first server?

Master

//run when the first server starts
If(first server){
    redis.flushall();
}
 //run code

Other separate clusters (running on different port/script)

//run when the first server starts
If(first server){//should be false now
    redis.flushall();
}
 //run code

Overview

Server 1 -- call flushall once (clean Redis memory)
Server 2 -- dont call flushall
Server 3 -- dont call flushall
...
Server n -- dont call flushall

Is there any way of doing this sort?

By the way, I'm using AWS hosting, which automatically duplicates and scales my server

Vardan Betikyan
  • 354
  • 5
  • 20
  • Does this answer your question? [In node.js, how to declare a shared variable that can be initialized by master process and accessed by worker processes?](https://stackoverflow.com/questions/10965201/in-node-js-how-to-declare-a-shared-variable-that-can-be-initialized-by-master-p) – O. Jones Dec 05 '20 at 12:01
  • There's no shared memory between instance of a cluster. – O. Jones Dec 05 '20 at 12:02
  • Yes and no. The question posted is for a script running on 1 server which has multiple clusters inside, and would work perfectly for what I'm trying to do. But in my case, each cluster is being ran on a separate server. Essentially, I need a Master for these separate horizontally scaled servers – Vardan Betikyan Dec 05 '20 at 12:20

1 Answers1

0

You can consider getting each separate nodejs process to ask their shared redis server for the current time.

let redisTime
redisConnection
    .timeAsync()
    .then ( timedata => {
       redisTime = timedata[0]
     })

It's a way to get what you want without having to push a value to redis.

O. Jones
  • 103,626
  • 17
  • 118
  • 172