Node.js Redis的lpush错误

我正在使用node.js和redis制作一个Web应用程序。 我想将每个传入的请求推送到一个redis队列,然后推送到数据库。 但是每次程序到达lpush命令时都会报错。 这是我的index.js代码,

var express = require('express'); var app=express(); var http = require('http').Server(app); var io=require('socket.io')(http); var qs=require('querystring'); var redis=require('redis'); var client = redis.createClient(); var count=0; var parseString = require('xml2js').parseString; //var countm=1; //var counte=1; app.get('/adminm', function(req, res){ res.sendfile('adminmovies.html'); }); app.get('/admine', function(req, res){ res.sendfile('adminevents.html'); }); app.post('/', function(req,res){ count=count+1; var body=""; req.on('data',function(data){ body+=data; }); req.on('end',function(){ console.log(body); var xml=body; var parsed=""; parseString(xml, function(err,result){ console.dir(result); parsed=result; }); //var post=qs.parse(body); io.emit('count1',count); redis.lpush('events',parsed); //console.log(post); }); }); /*io.on('connection',function(socket){ });*/ http.listen(3000, function(){ console.log('listening on *:3000'); }); 

而错误是,

 TypeError: undefined is not a function at IncomingMessage.<anonymous> (/home/kevin/Desktop/express-app/index.js:37:8) at IncomingMessage.emit (events.js:104:17) at _stream_readable.js:902:16 at process._tickCallback (node.js:343:11) 

我如何解决它?

您正在创buildredis客户端,但不在任何地方使用它。

在第37行中,您直接在导入的模块上调用lpush

  redis.lpush('events',parsed); 

lpush是未定义的。