Python中session与memcached或redis有什么区别?
I am confused about session,memcached/redis.
I often store the login infor into a memcached server or a redis, and then could we call that is a session?
if not,what does a session point and what's the
difference between memcached/redis and session? I have looked up into google,but I can not understand it still.
So,could you do me a favor? Thanks in advance!
Append:
I am a new fish on HTTP, and if this question makes you unhappy, you'd better to forget it. LOL...
Python中session与memcached或redis有什么区别?
session 是一种意图,一种妄图在无状态的 HTTP 里标记每个 client 状态的意图。
这个意图的实现需要 6 个组成步骤:
1,server 生成标明 client 的标记。(用什么方式标明?例:session 对象及其 sessionID )
2,把这个标记存储在 server 端。(存在哪里?例:磁盘文件)
3,把这个标记发往 client。(通过什么方式发送?例:Set-Cookie 头)
4,client 存储这份标记。(如何存储?例:Cookie 存储)
5,client 下次请求的时候,携带这份标记。(如何确保自动携带?通过什么东西承载?例:Cookie 头)
6,server 端根据标记去 2 里面找到对应的 client。
session 是一种机制。
而 redis/memcache 只是用来存储标记的位置而已,他们只负责第 2 点部分。
简单说,session是抽象概念,memcached/redis是具体工具。
session(会话)的核心是在多次HTTP请求间保持用户状态。它本身不规定存储方式,可以存在文件、数据库、内存或专门的缓存服务里。
memcached和redis是实现session存储的两种流行方案,属于键值存储。它们常被用作session后端,因为速度快(内存存储)、支持分布式(多服务器共享session)。
主要区别:
- 角色不同:session是功能需求(保持状态),memcached/redis是技术方案(存储数据)。
- 数据特性:session数据通常是临时的(用户退出即失效),而memcached/redis可存任何需要缓存的临时数据,不限于session。
- 使用方式:你可以在Flask/Django中配置session后端为redis,这样session机制就用redis来存数据了。
总结:session是“要做什么”,memcached/redis是“用什么来做”之一。
Well, I agree with you on session is an intention and it is also a mechanism. But, I wonder know who carries out the first step. A web server,like Nginx, Apache HTTP or others?
session 是数据, redis/memcached 是存储数据的手段
Web 服务器不负责生成,是你的应用生成的。没有 Session, 所有的 HTTP 功能都能正常工作,只是服务器不知道对方是谁了。甚至你可以自己通过 token 来模拟 session 的所有功能。
另外,英语不好为啥不用中文呢 orz
一般是应用服务器。例如:PHP、Tomcat 等。nginx 一般不管这事。
装老外 666
Well,I also know my English poor, and I am doing my best to improve it. Applying is a basic way to perfect my English, isn’t it? But,thank you all the same.
if you do not like it, just ignore it. Thanks all the same.
#9 并不是「我」不喜欢。
事实上我对你或者这个帖子本身并没有什么特别的看法,只是在提醒你这样的行为在一个公共社区并不合适,以免你遗漏这一点。这是个公序良俗的问题。
当然你听不听也随意,如果你不喜欢这种意见一样可以忽略我。
That’s fine.
Well,I wouldn’t like to make a argument.
> Well,I wouldn’t like to make a argument.
^[0]
Oh sure you did. If you want to take a stance and ask others to be quiet for disagreeing with you, surely your actions speak louder than your words.
[0] https://www.englishpage.com/articles/a-vs-an.htm
That does not make sense for me. The end. LOL

source: https://xkcd.com/1357/
假如看不懂的话: http://xkcd.tw/1357
got it.
小建议:如果你想更好地学习英文,请直接去英文社区,提问上 StackOverflow 嘛。不比在这里发个英文帖然后底下一堆中文回复的好吗?
英文标点后面要加空格
遇到 2 楼是你的福气,好好感谢他
也有客户端存储的 session,比如存在 cookie 里。
session 实现机制五花八门,重要的是理解 session 的本质: 在一个没有上下文的环境里试图恢复上下文
yep,flyinghost is nice and patient.
楼主你要是中国人,那么请用中文,如果你是老外,我们一点意见都没有,还会夸赞你好学。谢谢。
你是询问别人,那么尊重被询问人的建议也是应该的,键盘侠路过
I agree with you.
#16 网站很有趣,收藏了。感谢。
这种 Chinglish 看着太辣眼睛了。已经降权这个账号 -8。
#27 哈哈哈,我还想回复楼主几个语法错误呢,不过看他回复 的态度,我觉得又没有必要了。
想练英文应该去 SO 或者 Reddit 在中文网站上用英文纯属装 B 而且只会越来越 Chinglish
心疼楼主 1s. The end. LOL
所以,能请教一下吗?我该怎么转变我这种中式英语或者说中式思维了,因为确实学英语没多久,大概两个月吧?刚看了一些语法书,然后尝试着去造了句子.我也知道自己输入的不够,但是我的确想掌握英语,毕竟刚学的东西容易忘,如果要掌握的法就是用。我目前确实没有太多机会去给人写 email 或者直接沟通?我目前还没有找到比较好的方法,我能做的是造句。你如果你有比较好的方法,那么可以推荐给我吗?
我很好奇在你眼里我是什么态度。我的确不想争论跟他争论。
你是对的,但是 stack overflow 的问题门槛很高。你知道的。
去一个周围大部分人都只讲英语的环境。比如美国。
1 楼正解


