2

I have a project in Node.js where I used MemoryStore from express-session, but when I changed to use the session with redis (connect-redis) I receive the error ERR wrong number of arguments for 'set' command when accessing any page and cannot log in (because the session is not created, or is created incorrectly).

Trying to find why this is happening I created a simple project to see what is causing the error, but even after a lot of search I could not find the reason. I followed the instructions in https://github.com/tj/connect-redis and saw a lot of examples here in https://stackoverflow.com/ but the error is still happening. I tested in more ways (commented lines and others), but it's still happening. It only occurs when acessing a page (localhost:3000, there's only this page in this test), not on the server start.


The package.json file:

{
  "name": "test",
  "description": "Test",
  "version": "0.0.1",
  "private": false,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "^4.13.1",
    "express-load": "^1.1.15",
    "express-session": "^1.13.0",
    "cookie-parser": "^1.4.1",
    "redis": "^2.4.2",
    "connect-redis": "^3.0.2",
    "ejs": "^2.4.1"
  }
}

The app.js file:

const SECRET = 'test';

var express = require('express')
  , load = require('express-load')
  , expressSession = require('express-session')
  , cookieParser = require('cookie-parser')
  , cookie = cookieParser(SECRET)
  //, cookie = cookieParser()
  , redis = require('redis')
  , RedisStore = require('connect-redis')(expressSession)
  //, redisClient = redis.createClient()
  , redisClient = redis.createClient({host: '127.0.0.1', port: '6379'})
  , store = new RedisStore({client: redisClient})
  //, store = new RedisStore({host: '127.0.0.1', port: '6379'})
  //, store = new expressSession.MemoryStore()
  , session = expressSession({
      store: store,
      secret: SECRET, 
      resave: true, 
      saveUninitialized: true
    })
  , app = express()
  , server = require('http').Server(app)
;

app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(cookie);
app.use(session);

load('controllers')
  .then('routes')
  .into(app)
;

server.listen(3000, function() {
  console.log('Testing...');
});

If I comment , store = new RedisStore({client: redisClient}) and uncomment , store = new expressSession.MemoryStore(), I don't receive the error and it works fine with sessions. This test project is very simple and I find it weird that the error still happens, when I do the same thing like many other examples that I saw.

This test project - aside from the node_modules - only has 1 page /views/home/index.ejs, 1 controller /controllers/home.js and 1 route /routes/home.js, but they are very simple and the only thing they do is lead the user to the simple page /views/home/index.ejs, so the error must not be in one of those.


Edit

The error stack trace:

[path]\test>npm start

> [email protected] start [path]\test
> node app.js

Testing...
Error: ERR wrong number of arguments for 'set' command
    at JavascriptReplyParser._parseResult ([path]\test\node_modules\redis\lib\parsers\javascript.js:43:16)
    at JavascriptReplyParser.try_parsing ([path]\test\node_modules\redis\lib\parsers\javascript.js:114:21)
    at JavascriptReplyParser.run ([path]\test\node_modules\redis\lib\parsers\javascript.js:126:22)
    at JavascriptReplyParser.execute ([path]\test\node_modules\redis\lib\parsers\javascript.js:107:10)
    at Socket.<anonymous> ([path]\test\node_modules\redis\index.js:131:27)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

1 Answer 1

1

Update your version of Redis server.

https://github.com/redis/redis-rb/issues/372

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply, now I fixed the problem. The redis I was using was in version 2.5.3, and it seems fine. But for some reason there was no directory \connect-redis\node_modules\redis, so I don't know if the connect-redis was trying to take an older global version of redis or something like that, but the problem was probably the version of redis used by connect-redis (in the package.json of connect-redis, there is "redis": "^2.1.0", so maybe it was trying to use an out of date redis?). I just removed and installed connect-redis again and it has now the redis directory in version 2.5.3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.