3

Django's builtin cached_db session allows me to use memcached to store session data, and write through to db for persistence.

While some applications use redis as their session store (instagram for one).

What is the pros and cons of these solutions?

p.s. I am not asking about the comparison between memcached and redis, which this question Memcached vs. Redis? already provides very good answers. I am asking about which one is better in case of a session system.

Community
  • 1
  • 1
NeoWang
  • 13,687
  • 19
  • 61
  • 112

2 Answers2

2

In Memcached keys are expired when memory limit is reached even if their ttl is still due. This way some of your users will loose their sessions. In Redis you don't have memory limit by default, so you won't run into this problem. You need, however, manage your memory to ensure that Redis always has enough memory. You can also switch on memory limit in Redis making it to behave similar to Memcached (see MAXMEMORY configuration option).

Also take a look at Cookie-based sessions.

Suor
  • 2,393
  • 1
  • 18
  • 26
0

Today I would say Redis is a better choice. It offers, slightly more, out of the box functionality, like clustering. It is widely supported (i.e. ElastiCache on AWS) and there is a great django-redis library available for simple integration.

vladko
  • 930
  • 13
  • 21