代码空间


摘要(Abstract)

Team Introduction Acknowledgment Source Design Policy Model Policy Life Cycle Implementation Policy Manager Policy Types Firewall Policy REST API NAT Policy Connectivity policy Installation Operation Policy Manager Policy Types Creation of New Policy Types Helper functions for validations REST API 介绍 承认 资源 设计 政策模型 政策生命周期 履行 政策经理 政策类型 防火墙政策 NAT政策 连通政策 安装 手术 政策经理 政策类型 创建新的政策类型 帮助程序用于验证


主题(Topic)

项目(Project)
geerlingguy/ansible-role-daemonize leprosus/golang-daemon bfontaine/homer Cvar1984/ReverseTCP guchangsheng/DefenderService Firehed/php-daemon DougEverly/daemonize.cr silverwind/daemonize-process arbv/daemonize thesharp/daemonize knsd/daemonize jwodder/daemail mutable-dan/daemon UUInc-co/lil-c-daemon_legacy ops-baidu/avalokita DarthUdp/daemonize-me hipek8/p6-UNIX-Daemonize jedisct1/rust-daemonize-simple CNTRUN/Termux-command org.apache.poi poi ${poi_version} org.apache.poi poi-ooxml-schemas ${poi_version} org.apache.poi poi-scratchpad ${poi_version} org.apache.poi poi-ooxml ${poi_version} org.apache.activemq activemq-all 5.8.0 org.apache.activemq activemq-pool ${activemq_version} org.apache.xbean xbean-spring 3.16 javax.servlet servlet-api ${javax.servlet-api.version} provided javax.servlet.jsp jsp-api 2.1 provided javax.servlet jstl 1.2 redis.clients jedis 2.7.2 org.redisson redisson 1.0.2 org.slf4j jcl-over-slf4j ${slf4j.version} org.slf4j slf4j-log4j12 ${slf4j.version} org.springframework.data spring-data-redis 1.6.2.RELEASE org.springframework spring-webmvc ${spring.version} commons-logging commons-logging org.springframework spring-tx ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-context-support ${spring.version} org.springframework.data spring-data-redis 1.6.2.RELEASE org.springframework spring-orm ${spring.version} org.springframework spring-jms ${spring.version} org.springframework.session spring-session ${spring.session.version} org.springframework spring-core ${spring.version} redis-config.xml [html] view plain copy 在CODE上查看代码片派生到我的代码片 redis.properties [plain] view plain copy 在CODE上查看代码片派生到我的代码片 redis.host.ip=192.168.0.101 redis.host.port=6379 redis.maxTotal=1000 redis.maxIdle=100 redis.maxWait=2000 redis.testOnBorrow=false redis.testOnReturn=true web.xml [html] view plain copy 在CODE上查看代码片派生到我的代码片 contextConfigLocation classpath:/spring/redis-conf.xml springSessionRepositoryFilter org.springframework.web.filter.DelegatingFilterProxy springSessionRepositoryFilter /* 30 encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter /* dispatcher org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:/spring/spring-mvc.xml 1 dispatcher / org.springframework.web.context.ContextLoaderListener sessionServlet sample.SessionServlet sessionServlet /servlet/session index.jsp 这边主要是一个: [html] view plain copy 在CODE上查看代码片派生到我的代码片 springSessionRepositoryFilter org.springframework.web.filter.DelegatingFilterProxy springSessionRepositoryFilter /* 30 这个filter一定要写在一切filter之前 SessionController [java] view plain copy 在CODE上查看代码片派生到我的代码片 package sample; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * Created by mk on 15/1/7. */ @Controller @EnableRedisHttpSession public class SessionController { @RequestMapping("/mySession") public String index(final Model model, final HttpServletRequest request) { if (request.getSession().getAttribute("testSession") == null) { System.out.println("session is null"); request.getSession().setAttribute("testSession", "yeah"); } else { System.out.println("not null"); } return "showSession"; } } showSession.jsp文件 [html] view plain copy 在CODE上查看代码片派生到我的代码片 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> showSession <% String sessionValue=(String)session.getAttribute("testSession"); %>

Session Value From Servlet is: <%=sessionValue%>

测试 保证我们的redise-server是启动的,然后我们启动起这个web工程后使用: http://localhost:8080/webpoc/mySession访问一下这个controller 此时我们使用redis客户端工具连入查看spring session是否已经进入到了redis中去。 在redis客户端工具连入后我们可以在redis console中使用keys *来查看存入的key,LOOK,spring的session存入了redis中去了。 再来看我们的eclipse后台,由于我们是第一次访问这个controller,因此这个session为空,因此它显示如下: 我们在IE中再次访问该controller 由于之前的session已经存在于redis了,因此当用户在1800秒(30分钟)内再次访问controller,它会从session中获取该session的key testSession的值,因此eclipse后台打印为not null。 SpringRedisTemplate + Redis 讲过了spring session+redis我们来讲使用spring data框架提供的redisTemplate来访问redis service吧。说实话,spring这个东西真强,什么都可以集成,cassandra, jms, jdbc...jpa...bla...bla...bla...Spring集成Barack Hussein Obama? LOL :) pom.xml 不用列了,上面有了 redis-conf.xml 不用列了,上面有了 web.xml 也不用列了,上面也有了 SentinelController.java 我们就先用这个名字吧,后面我们会用它来做我们的redis sentinel(哨兵)的高可用(HA)集群测试 [java] view plain copy 在CODE上查看代码片派生到我的代码片 package sample; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisSentinelPool; import util.CountCreater; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * Created by xin on 15/1/7. */ @Controller public class SentinelController { @Autowired private StringRedisTemplate redisTemplate; @RequestMapping("/sentinelTest") public String sentinelTest(final Model model, final HttpServletRequest request, final String action) { return "sentinelTest"; } @ExceptionHandler(value = { java.lang.Exception.class }) @RequestMapping("/setValueToRedis") public String setValueToRedis(final Model model, final HttpServletRequest request, final String action) throws Exception { CountCreater.setCount(); String key = String.valueOf(CountCreater.getCount()); Map mapValue = new HashMap(); for (int i = 0; i < 1000; i++) { mapValue.put(String.valueOf(i), String.valueOf(i)); } try { BoundHashOperations boundHashOperations = redisTemplate .boundHashOps(key); boundHashOperations.putAll(mapValue); System.out.println("put key into redis"); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } return "sentinelTest"; } } 打开IE,输入:http://localhost:8080/webpoc/setValueToRedis 观察我们的后台 然后使用redis client连入后进行查看 看。。。这个值key=1的,就是我们通过spring的redisTemplate存入进去的值,即使用下面这段代码进行存入的值: [java] view plain copy 在CODE上查看代码片派生到我的代码片 for (int i = 0; i < 1000; i++) { mapValue.put(String.valueOf(i), String.valueOf(i)); } try { BoundHashOperations boundHashOperations = redisTemplate.boundHashOps(key); boundHashOperations.putAll(mapValue); 如何你要存入一个简单的如key=test value=hello,你可以这样使用你的redisTemplate [java] view plain copy 在CODE上查看代码片派生到我的代码片 redisTemplate.execute(new RedisCallback() { @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.set( redisTemplate.getStringSerializer().serialize( "test"), redisTemplate .getStringSerializer() .serialize("hello")); return null; } }); 是不是很方便的哈?结束第一天的教程,明天开始搭建redis集群。" class="topic-tag topic-tag-link"> Redis-