Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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

Problem

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?

Problem courtesy of: kocodude

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.

Solution courtesy of: Linus Gustav Larsson Thiel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

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

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×