且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查redis是否正在运行->节点js

更新时间:2023-11-28 08:27:22

我过去的操作方式是在通过

How I have done this in the past is in between setting up the redis connection via

var client = redis.createClient(global.redis.port, global.redis.host);

并实际上启动我的应用程序(无论是快速应用程序还是自定义应用程序),我只是执行一个非常简单的查询,例如:

and actually starting my application, whether that be express or a custom app, I just do a very simple query, such as:

client.get(this.testKey, function(err,res) {
  if(err) 
    throw err;

  if(res === expectedValue)
    return startApp();
});

基本上,只需将代码放入要在redis查询的回调中启动您的应用,然后您将根据结果知道redis是否正在运行.

Essentially just put the code to start your app inside of the callback to a redis query, and you will then know if redis is running based on the result.