【问题标题】:Redis, wrong number of arguments for 'set' command node.jsRedis,'set'命令node.js的参数数量错误
【发布时间】:2021-02-23 15:40:25
【问题描述】:

我是使用 Redis 存储会话的最简单的 nodejs 应用程序。我已经在windows上下载并启动了reds-server,但它会弹出以下错误消息

ReplyError: ERR wrong number of arguments for 'set' command
    at parseError (D:\Org\Projects\Up\Image metadata\Lab\Login with store\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (D:\Org\Projects\Up\Image metadata\Lab\Login with store\node_modules\redis-parser\lib\parser.js:302:14)

我的简单 node.js express 应用如下

const express = require("express");
const session = require("express-session");
const redis = require("redis");
const connectRedis = require("connect-redis");
const bodyParser = require("body-parser");

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));

const RedisStore = connectRedis(session);

const redisClient = redis.createClient({
    host:"localhost",
    port:6379
})


app.use(session({
    store: new RedisStore({client: redisClient}),
    secret:"shhhhh4",
    resave: false,
    saveUninitialized: false,
    cookie:{
        secure: false,
        httpOnly: false,
        maxAge: 5 * 30 * (24 * (1000 * 60 * 60))
    }
}));


app.get("/", (req,res)=>{
    const sess = req.session;
    if (sess.username && sess.password) {
        if (sess.username) {
            res.write(`<h1>Welcome ${sess.username} </h1><br>`)
            res.write(
                `<h3>This is the Home page</h3>`
            );
            res.end('<a href=' + '/logout' + '>Click here to log out</a >')
        }
    } else {
        res.sendFile(__dirname + "/login.html")
    }
});


app.post("/login", (req, res) => {
    const sess = req.session;
    const { username, password } = req.body
    sess.username = username
    sess.password = password
    console.log(req.body);
    // add username and password validation logic here if you want.If user is authenticated send the response as success
    res.end("success")
});

有什么问题?我已经安装了最新的导入模块,但仍然收到错误

我正在使用Redis server version 2.4.5
和 redis 和 redis-connect 6.14.6

【问题讨论】:

  • 你运行的是什么版本的redis?
  • @eol 我正在使用 Redis server version 2.4.5 和 redis 和 redis-connect 6.14.6

标签: node.js express session redis node-redis


【解决方案1】:

您需要更新到较新版本的 redis,因为您的版本已经过时并且不支持 set 命令的给定选项,请参阅github issue 了解更多详细信息。

【讨论】:

  • 谢谢,我更新了,npm connect-redis --versionnpm redis --version 现在给我 6.14.6 但问题仍然存在。我得到同样的错误
  • 当我将服务器应用程序本身更新到 3.0.5 时它工作了
  • 是的,这就是我的意思 - 很高兴,你成功了 :)
猜你喜欢
  • 2017-09-22
  • 2015-03-21
  • 1970-01-01
  • 2020-12-28
  • 2021-08-09
  • 2021-06-18
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
相关资源
最近更新 更多