Tomcat 使用Redis存储Session
2016-10-02 17:28
417 查看
Tomcat Redis Session Github 地址。
commons-pool2-2.2.jar,jedis-2.5.2.jar,tomcat-redis-session-manager-2.0.0.jar 这三个包,将其放到 tomcat 目录下的lib目录下。
修改tomcat 的conf目录下的 context.xml 件。
在Context中插入下面的代码。
更详细的方式可以查看github的配置。
这样就配置好了一件简单的使用redis存储session的环境,对于集群可以采取相同的配置。
测试Servlet:
启动tomcat,访问 http://localhost:8080/myhttp则可以在redis下看到
证明环境已经配置成功,可以使用了。
commons-pool2-2.2.jar,jedis-2.5.2.jar,tomcat-redis-session-manager-2.0.0.jar 这三个包,将其放到 tomcat 目录下的lib目录下。
修改tomcat 的conf目录下的 context.xml 件。
在Context中插入下面的代码。
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="localhost" port="6389" database="0" maxInactiveInterval="60" />
更详细的方式可以查看github的配置。
这样就配置好了一件简单的使用redis存储session的环境,对于集群可以采取相同的配置。
测试Servlet:
@WebServlet(urlPatterns="/myhttp") public class MyHttpServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取session HttpSession httpSession=request.getSession; httpSession.setAttribute("name","name"); //设置为0 永不过期 httpSession.setMaxInactiveInterval(1000); //使httpserssion无效 // httpSession.invalidate; System.out.println(httpSession.getId); response.getWriter.print("http"); } }
启动tomcat,访问 http://localhost:8080/myhttp则可以在redis下看到
证明环境已经配置成功,可以使用了。
相关文章推荐
- tomcat使用redis存储共享session
- tomcat使用redis存储共享session
- Tomcat集群之使用Redis来存储集群Session
- Tomcat 使用Redis存储Session
- 使用redis作为php中session的存储介质
- 使用 Redis 来存储 Apache Tomcat 7 的 Session
- Nginx+Tomcat+Memcached 集群Session共享[memcached服务安装、tomcat使用memcache存储session、nginx安装配置实现tomcat负载均衡]
- 用Redis存储Tomcat集群的Session
- 用Redis存储Tomcat集群的Session
- tomcat7使用redis做session同步
- redis实战之使用redis存储session数据
- Tomcat利用Redis存储Session【单点redis和群集redis】
- tomcat 使用redis 管理session
- 分布式系统状态下redis存储asp.net session使用第三方Providers驱动
- 将Tomcat的Session数据存储在 Redis 库
- 用Redis存储Tomcat集群的Session
- 用Redis存储Tomcat集群的Session
- Tomcat7+Redis存储Session
- tomcat与redis链接redis存储session
- 用Redis存储Tomcat集群的Session