在后台启动Redis服务器后,Gulp任务被卡住

在后台启动Redis服务器后,Gulp任务被卡住,redis,gulp,Redis,Gulp,当我运行上面的startRedis gulp任务时,它会启动redis服务器,但从不退出 gulpfile.js var shell = require('gulp-shell'); gulp.task('startRedis', shell.task([ 'redis-2.8.15/src/redis-server > /dev/null &' ])); 如果我停止redis服务器,它就会返回。不确定出了什么问题,请提供帮助。如果您只是想立即完成任务,最好使

当我运行上面的startRedis gulp任务时,它会启动redis服务器,但从不退出

gulpfile.js  

var shell = require('gulp-shell');

gulp.task('startRedis', shell.task([  
  'redis-2.8.15/src/redis-server > /dev/null &'  
]));

如果我停止redis服务器,它就会返回。不确定出了什么问题,请提供帮助。

如果您只是想立即完成任务,最好使用
子进程。直接执行:

$gulp startRedis
[19:03:42] Using gulpfile ~/myhome/gulpfile.js  
[19:03:42] Starting 'startRedis'...  

如果您希望gulp立即退出,从而创建一个僵尸redis服务器进程,这可能会更复杂。

我曾使用gulp shell启动我的redis服务器,但不是每次在我的节点应用程序之前都启动它

使用
exec=require('child_process')。exec

我可以做得更安全些

var exec = require('child_process').exec;

gulp.task('startRedis', function() {
  exec('redis-2.8.15/src/redis-server', function(err, stdout, stderr) {
    if (err) {
      console.log(err, stdout, stderr);
    }
  });
});
gulp.task('dev-redis', function() {
    exec('redis-server --port 7777 --notify-keyspace-events KExe', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
    });
});
gulp.task('dev',['dev-redis'], function() {

    /*
    * Add on('change').on('restart') allow to add listeners
    * Even if you don't precise callback functions, it triggers the change/restart event
    * */
    nodemon({ script: 'index.js', nodeArgs: ['--debug'], env: { 'NODE_ENV': 'development' }  })
        .on('change', [])
        .on('restart', function () {
            console.log('restarted!');
        });
});