In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article shows how redis stores session, and the code is concise and easy to understand if you encounter this question in your daily work. I hope you can find a solution to your questions through this article.
Redis storage session needs to consider:
How is session data stored in Redis? When does the session property change trigger storage?
Achieve:
Considering that the structure of data in session is similar to that of map, it is more appropriate to use hash in redis to store session data. If a single value is used to store session data without locking, there will be the problem of session coverage. Therefore, using hash to store session only saves the data that changes the session attribute each time, which avoids lock processing and has better performance.
If storage is triggered every time the attribute of session is changed, multiple redis writes will be triggered when more session attributes are changed, which will also affect performance. We write session once after each request is processed, and write the changed attributes.
If no changes are made to session this time, redis writes will not be done. Only when the session that has not changed exceeds a time threshold (does not change the threshold of session refresh expiration time), session save will be triggered so that session can extend the validity period.
There are two ways to implement:
Session centralized storage (redis,memcached,hbase, etc.).
Replication of session data on different servers, the advantages and disadvantages of the two ways, we should know at a glance.
Implementation scheme based on session centralized storage:
Add Filter, intercept requests, and wrap HttpServletRequest
Rewrite the getSession method, get session data from session storage, and return a custom HttpSession implementation
After generating a new Session, write the sessionid to the cookie
After reading the above, have you mastered the method of saving session in redis? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.