Chapter 2. Anatomy of a Redis web application

This chapter covers

  • Login cookies
  • Shopping cart cookies
  • Caching generated web pages
  • Caching database rows
  • Analyzing web page visits

In the first chapter, I introduced you to what Redis is about and what it’s capable of. In this chapter, I’ll continue on that path, starting to dig into several examples that come up in the context of some types of web applications. Though I’ve simplified the problems quite a bit compared to what happens in the real world, each of these pieces can actually be used with little modification directly in your applications. This chapter is primarily meant as a practical guide to what you can do with Redis, and chapter 3 is more of a command reference.

To start out, let’s look at what we mean by a web application from the high level. Generally, we mean a server or service that responds over the HTTP protocol to requests made by web browsers. Here are the typical steps that a web server goes through to respond to a request:

1.  The server parses the request.

2.  The request is forwarded to a predefined handler.

3.  The handler may make requests to fetch data from a database.

4.  With the retrieved data, the handler then renders a template as a response.

5.  The handler returns the rendered response, which gets passed back to the client.

2.1. Login and cookie caching

2.2. Shopping carts in Redis

2.3. Web page caching

2.4. Database row caching

2.5. Web page analytics

2.6. Summary

sitemap