【问题标题】:How to run flushall only once among multiple clusters using Node.js and Redis?如何使用 Node.js 和 Redis 在多个集群中只运行一次 flushall?
【发布时间】:2021-03-17 06:34:34
【问题描述】:

在服务器启动时,我需要清理我的 Redis 内存。但是每次形成一个新的集群时,它都会调用 flushall 并清除内存中的所有内容。如何从一开始的第一台服务器只运行一次 flushall?

大师

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

其他单独的集群(在不同的端口/脚本上运行)

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

概览

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

有没有办法做到这一点?

顺便说一句,我使用的是 AWS 托管,它会自动复制和扩展我的服务器

【问题讨论】:

标签: javascript node.js redis cluster-computing


【解决方案1】:

您可以考虑让每个单独的 nodejs 进程向他们的共享 redis 服务器请求current time.

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

这是一种无需将值推送到 redis 即可获得所需内容的方法。

【讨论】:

  • 我编辑了问题和正文以获得更集中的示例。抱歉给您添麻烦了
  • 我也想到了这个,适用于之前的模糊问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-09
  • 1970-01-01
  • 1970-01-01
  • 2020-08-23
  • 2018-09-09
  • 1970-01-01
  • 2019-02-17
相关资源
最近更新 更多