How safe is it to store sessions with Redis?

后端 未结 3 1828
盖世英雄少女心
盖世英雄少女心 2020-12-12 09:37

I\'m currently using MySql to store my sessions. It works great, but it is a bit slow.

I\'ve been asked to use Redis, but I\'m wondering if it is a good idea because

3条回答
  •  有刺的猬
    2020-12-12 10:02

    Redis is perfect for storing sessions. All operations are performed in memory, and so reads and writes will be fast.

    The second aspect is persistence of session state. Redis gives you a lot of flexibility in how you want to persist session state to your hard-disk. You can go through http://redis.io/topics/persistence to learn more, but at a high level, here are your options -

    1. If you cannot afford losing any sessions, set appendfsync always in your configuration file. With this, Redis guarantees that any write operations are saved to the disk. The disadvantage is that write operations will be slower.
    2. If you are okay with losing about 1s worth of data, use appendfsync everysec. This will give great performance with reasonable data guarantees

提交回复
热议问题