Redis Real-Life notes (2)-2nd. Building a web App using Redis

Source: Internet
Author: User

2nd. Building a web App using Redis

Main contents of this Chapter 1. Login Cookie2. cookie3. Cache generated page 4. Cache database rows 5. Analyze Web Access records everything in this chapter revolves around discovering and resolving fake web retailer, a fictitious big online store, The store will have about 5 million different users each day, who will bring 100 million clicks to the site and purchase more than 100,000 items from the site. The reason we set the number of data for fake WEB retailer is particularly large, considering that all the solutions (and some of their variants) that can be successfully enumerated in the context of large data volumes are actually used in the production environment. To be more specific,by transferring part of a traditional database's data processing tasks and storage tasks to Redis, 2.1 Login and cookie cachingWhenever we log in to an Internet service (such as a bank account or email), these services use cookies to record our identity. A cookie consists of a small amount of data, and the Web site asks our browser to store the data and pass it back to the service each time the request is sent. For cookies used to log in,There are two common ways to store login information in a cookie:one is a signed (signed) Cookie,the other is a token cookie. A signature cookie typically stores a user name, possibly a user ID, the last time a user successfully logged in, and any other information that the site feels useful. In addition to information about the user, the signature cookie contains a signature that the server can use tosignature to verify that the information sent by the browser is unaltered (such as changing the login user name in the cookie to another user). The token cookie is in the cookiestores a bunch of random bytes as tokens that the server can look for in the database for the owner of the token based on the token. Over time, the old token is replaced with a new token.

Case: Use Redis to re-implement the login cookie feature to replace the login cookie feature currently implemented by the relational database. 1. A hash to store the mapping between the login cookie token and the logged-on user 2. Each time the user browses the page, the program stores the user's login hash. The information inside is updated and the user's token and current timestamp are added to the ordered collection of the most recently logged-in user; If a user is browsing a product page, the program also adds the item to the ordered collection of items that the user has recently browsed and trims the ordered set when the number of items recorded exceeds 25. 3. Because the memory required to store session data is increasing over time, we need to periodically clean up old session data2.2 using Redis to implement a shopping cartThe shopping cart information is also stored in Redis, and the shopping cart is referenced using the same cookie ID as the user's session cookie.2.3 Web Cache2.4 data row CacheIn order to deal with the heavy load of the promotion, we need to cache the data rows by writing a daemon function that runs continuously, allowing the function to cache the specified rows of data into Redis and not periodically update them (hotspot cache?).2.5 web AnalyticsOrdered set ordering

Redis Real-Life notes (2)-2nd. Building a web App using Redis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.