koajs / koa-redis

Redis storage for Koa session middleware/cache with Sentinel and Cluster support
MIT License
353 stars 40 forks source link

Prevent invalid sessions on restart of application #31

Open crunchtime-ali opened 7 years ago

crunchtime-ali commented 7 years ago

I am using koa-generic-session with koa-redis. Everytime I restart my application all my sessions are invalid. I use it together with Passport and need to login again. How can I prevent this?

I setup the store with only basic configuration items:

const redisStore = require('koa-redis')
let store = redisStore({
      host: 'localhost',
      port: 6379
 })
DaAwesomeP commented 7 years ago

You can use session.client to directly access the Redis library functions and clear the table.

crunchtime-ali commented 7 years ago

How will that help me keeping the data after a restart? I want my sessions to remain valid.

DaAwesomeP commented 7 years ago

I'm sorry, I misunderstood. Are you explicitly setting keys?

crunchtime-ali commented 7 years ago

Yes, I do but right now I only set them like this: app.keys = ['keys', 'keykeys'];

DaAwesomeP commented 7 years ago

The only thing that I can think of is that the TTLs are running out or that Redis is clearing the DB after restart. Have you setup persistence in Redis?