在打字稿中设置connect-redis

时间:2018-11-08 03:17:01

标签: typescript

基于文档,这是创建redisstore的方法:

with open('filename', 'r') as f:
  for line in f.readlines():
    if line.find('search_string') != -1:
      # do stuff

我正在将它们转换为打字稿:

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

app.use(session({
    store: new RedisStore(options),...
}));

但是,我遇到一个错误。您如何转换这一行代码: import * as session from 'express-session'; import * as RedisStore from 'connect-redis'; app.use(session({ store: new (RedisStore(session))(options),... }));

2 个答案:

答案 0 :(得分:1)

我知道了:

import * as session from 'express-session';
import * as connectRedis from 'connect-redis';
let RedisStore = connectRedis(session);

app.use(session({
    store: new RedisStore(options),...
}));

答案 1 :(得分:0)

这有效:

import connectRedis from 'connect-redis';
import session from 'express-session';
const RedisStore = connectRedis(session);

 app.use(
        session({
            secret: 'secret',
            store: new RedisStore({host: '127.0.0.1', port: 6379}),
            resave: false,
            saveUninitialized: false
        })
    );