使用 Redis 存储会话有多安全? [英] How safe is it to store sessions with Redis?

查看:62
本文介绍了使用 Redis 存储会话有多安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 MySql 来存储我的会话.效果很好,但速度有点慢.

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

我被要求使用 Redis,但我想知道这是否是一个好主意,因为我听说 Redis 会延迟写入操作.我有点害怕,因为会话需要是实时的.

I've been asked to use Redis, but I'm wondering if it is a good idea because I've heard that Redis delays write operations. I'm a bit afraid because sessions need to be real-time.

有人遇到过这样的问题吗?

Has anyone experienced such problems?

推荐答案

Redis 非常适合存储会话.所有操作都在内存中执行,因此读写速度会很快.

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

第二个方面是会话状态的持久性.Redis 为您提供了很大的灵活性,可以让您将会话状态持久化到硬盘.您可以通过 http://redis.io/topics/persistence 了解更多信息,但是级别,这是您的选择 -

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. 如果您无法承受丢失任何会话,请在您的配置文件中设置 appendfsync always.有了这个,Redis 保证任何写操作都保存到磁盘.缺点是写入操作会比较慢.
  2. 如果您可以接受大约 1 秒的数据丢失,请使用 appendfsync everysec.这将在合理的数据保证下提供出色的性能
  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

这篇关于使用 Redis 存储会话有多安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆