本文介绍了Cookie和Redis会话存储之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不同节点上的2个应用程序之间共享会话;然而,我很困惑Cookie和Redis会话存储之间的区别;例如一个Cookie的会话可能是这样的:

I want to share sessions among 2 applications on different nodes; however, I am confused what the difference is between Cookie and Redis session stores; e.g. a cookie session might look like this:

rack.session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiJFN2YxZDMxMGE5YTNhZjc2NGM1NDBk%0AMzdiODQ0MjcyMzk5MzAxY2YyYzdhNDMwOWVkMzhiNWVlMmY2N2QwYzExNg%3D%3D%0A--ec4ec7b5a807c806e02e2811f4a11d05877a7698

在Redis中,会话存储可能如下所示:

In Redis, a session-store, might look like this:

rack:session:eb23c0a055e9e6de3b8ad51efd9g6260d647b2e61326e35f5ff59cd490bfb405"

,我很困惑如何可以共享这些会话,而在cookie的方法,一个请求携带会话的状态,我不能看到如何会话在Redis实际匹配状态在2个应用程序任何建议如何使用Redis /共享2个机架应用程序之间的会话状态。

However, I am confused how these sessions can be shared. Whereas in a cookie approach, a request carries the state of the session, I can't see how the session in Redis actually matches to state among 2 applications. Any advice how to use Redis / share session state among 2 rack apps?

推荐答案

Redis会话存储仍然使用cookie来跟踪会话id客户端。区别是存储在会话中保存的实际数据。使用cookie存储,它被填充到cookie中并与每个请求一起发送。使用redis-store,只有会话ID在cookie中传递,并且使用cookie中的会话ID从Redis检索实际的会话数据。以下是各种的详细说明。

The Redis session store still uses a cookie to track the session id client side. The difference is where the actual data that you stick in the session is stored. With the cookie store, it's stuffed into the cookie and sent back and forth with each request. With the redis-store, only the session id is passed in the cookie and the actual session data is retrieved from Redis using the session id in the cookie. Here's a great description of the various trade-offs with different session stores.

可能会与Cookie和Redis会话存储一起使用共享会话。请查看这两个问题的详细信息:

Sharing sessions might be made to work with both Cookie and and Redis session stores. Check out these two questions for details:

这篇关于Cookie和Redis会话存储之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!