Search code examples
node.jsexpressredisconnect-redis

Prevent setting TTL for connect-redis session to allow allkeys-lru for memory policy


I have set up a pretty simple RedisStore using connect-redis and redis packages. I have a dedicated box for my Session store and want to use the allkeys-lru maxmemory policy for eviction rather than a TTL.

It doesn't seem that connect-redis' store allows for setting no TTL (i tried using -1 in the options object when creating the store, looks like that sets a TTL of 0). Any suggestions on how to do this?

Also, does anyone see why this might be a bad practice?


Solution

  • Looking at the relevant source code, it seems like connect-redis won't let you use it without expiring the key. It seems to me that you have two options:

    • Write your own session store, inheriting from connect-redis' RedisStore but overriding set, or
    • Specify a huge maxAge, in order to have keys expiring far in the future.

    I don't see an issue with not expiring keys and using lru instead.