TypeError [ERR_INVALID_ARG_TYPE], express-session+redis 错误

TypeError [ERR_INVALID_ARG_TYPE], express-session+redis Error

我正在使用 typescript + express 进行开发

我想将 Redis 用于会话存储并且我安装了 redis、connect-redis 我的代码如下

import { createClient } from 'redis';
import * as RedisStore from 'connect-redis';
...
const client = createClient({
    url: 'redis://default:qwer1234@localhost:6379',
});
client.connect().then(() => {
    console.log('redis success');
});
...
app.use(
    session({
        secret: env.COOKIE_SECRET!,
        resave: false,
        saveUninitialized: false,
        store: new redisSession({
            client: client,
        }),
    })
);

我在下面写了代码来测试redis

app.get('/', (req, res) => {
    const sess = req.session;
    if (sess.key) {
        res.send(sess.key);
    } else {
        res.send('FAIL');
    }
});
app.post('/login', (req, res) => {
    const sess = req.session;
    const { username } = req.body;
    sess.key = username
    // add username and password validation logic here if you want.If user is authenticated send the response as success
    res.end('success');
});
app.get('/logout', (req, res) => {
    req.session.destroy((err) => {
        if (err) {
            return console.log(err);
        }
        res.send('OK');
    });
});

但是,在将值保存到会话时出现以下错误。 TypeError [ERR_INVALID_ARG_TYPE]:“chunk”参数必须是字符串类型或 Buffer 或 Uint8Array 的实例。接收到 Array

的一个实例

因为这个错误,之前使用内存存储实现的护照本地代码不起作用。 请帮帮我..

使用当前基于时间的redis 4.0版本出现问题,需要在redis设置中设置legacyMode: true

const client = createClient({
    url: yourURL,
    legacyMode: true,
});