我们使用单台 Tomcat 的时候不会有共享 sesssion 的疑虑,只要使用 Tomcat 的默认配置即可,session 即可存储在 Tomcat 上。但是随着业务的扩大,增加 Tomcat 节点构成 Tomcat 集群大势所趋,分布式带来了增加更大规模并发请求的优势,但是也随之到来了一个问题,每个 Tomcat 只存储来访问自己的请求产生的 session,如果 Tomcat-A 已经为客户端 C 创建了会话 session,那么 Tomcat-B 并不知道客户端已与集群中的 Tomcat-A 产生了会话,在访问时就会为 C 再创建一份 session,如果是基于 session 的验证会话权限的接口(如用户登录认证后才可访问的数据接口),将会导致在访问集群中不同节点的时候重复认证。session 的不共享导致原来的会话管理机制在 Tomcat 集群中无法工作。

由于本地环境的使用,所以搭建一个本地的 Redis 集群,本篇讲解 Redis 主从复制集群的搭建,使用的平台是 Windows。为了使得集群在一部分节点下线或者无法与集群的大多数节点进行通讯的情况下, 仍然可以正常运作, Redis 集群对节点使用了主从复制功能: 集群中的每个节点都有 1 个至 N 个复制品(replica), 其中一个复制品为主节点(master), 而其余的 N-1 个复制品为从节点(slave)。

Memcached or Redis? It’s a question that nearly always arises in any discussion about squeezing more performance out of a modern, database-driven Web application. When performance needs to be improved, caching is often the first step taken, and Memcached or Redis are typically the first places to turn.

These renowned cache engines share a number of similarities, but they also have important differences. Redis, the newer and more versatile of the two, is almost always the superior choice.