无法将redis服务器与快速节点js app集成

时间:2018-03-16 07:17:04

标签: node.js redis kue

我是Node.js的新手,我一直在尝试创建一个与KUE库集成的小应用程序,用于任务排队。

当我尝试运行该应用时,node app.js我收到以下错误:

{ ReplyError: ERR wrong number of arguments for 'set' command
    at parseError (.......\node_modules\redis-parser\lib\parser.js:193:12)
    at parseType (........\node_modules\redis-parser\lib\parser.js:303:14)
  command: 'SET',
  args: [ 'promotion:lock', 'H5BCCsomeRandomString==', 'PX', 2000, 'NX' ],
  code: 'ERR' }

我确实在很多地方看到了这个错误,但它们似乎都不是我问题的解决方案。

这是我的app.js

var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var dotenv = require('dotenv');
dotenv.load();

var queue = require('./routes/queueJob');

var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
  secret: 'secret',
  resave: true,
  saveUninitialized: true
}));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/jobs', queue);

app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: err
  });
});

app.listen(3000);

这是routes / queuejob.js

var express = require('express');
var router = express.Router();
var kue = require('kue'),
  jobs = kue.createQueue();
var env = {};


jobs.on('ready', () => {
  console.info('Queue is ready!');
});

jobs.on('error', (err) => {
  console.error('There was an error in the main queue!');
  console.error(err);
  console.error(err.stack);
});

router.get('/addnewjob', function(req, res) {
  let callback = function() {
    console.log('Callback has been triggered');
  }
  newJob('Request Job', callback);
  res.end('Successfully added a new job');
});

function newJob(name, callback) {

  name = name || 'Default_Name';

  var job = jobs.create('new job', {
    name: name
  });

  job
    .on('complete', function() {
      console.log('Job', job.id, 'with name', job.data.name, 'is done');
      callback();
    })
    .on('failed', function() {
      console.log('Job', job.id, 'with name', job.data.name, 'has failed');
      callback();
    })

  job.save();
}

jobs.process('new job', function(job, done) {
  setTimeout(function() {
    console.log('Job Processing finished');
  }, 5000);
  done();
});

module.exports = router;

由于错误消息中没有多少我不确定如何解决此问题。我真的很感激一些帮助。

1 个答案:

答案 0 :(得分:0)

Redis中的SET命令具有以下格式:

SET key value [EX seconds] [PX milliseconds] [NX|XX]

在您的错误中,您似乎正在尝试使用与许多与格式不匹配的争论的SET命令:

  command: 'SET',
  args: [ 'promotion:lock', 'H5BCCsomeRandomString==', 'PX', 2000, 'NX' ],