Spring集成Redis配置
文件清单:
reids.properties
applicationContext.xml
RedisTest .java
1)reids.properties
#最大分配的链接数
redis.pool.maxActive=1024
#最大能够保持空闲状态的链接数
redis.pool.maxIdle=200
#当池内没有返回链接时,最大等待时间
redis.pool.maxWait=1000
#当调用borrow Object方法时,是否进行有效性检查
redis.pool.testOnBorrow=true
#当调用return Object方法时,是否进行有效性检查
redis.pool.testOnReturn=true
#IP
redis.ip=127.0.0.1
#Port
redis.port=6379
#我的配置 Redis settings
redis.host=192.168.59.130
redis.port=6379
redis.pass=neusoft,123
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true
2)applicationContext.xml
location="classpath:config/db.properties,classpath:config/redis.properties" /> class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> class="org.springframework.data.redis.serializer.StringRedisSerializer" /> class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> public class RedisTest { public static void main(String[] args) { /** * Redis五大类型:字符串(String)、哈希/散列/字典(Hash)、列表(List)、集合(Set)、有序集合(sorted set)五种 Controller:@Resource RedisTemplate 总括: redisTemplate.opsForValue();//操作字符串 redisTemplate.opsForHash();//操作hash redisTemplate.opsForList();//操作list redisTemplate.opsForSet();//操作set redisTemplate.opsForZSet();//操作有序set */ ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); RedisTemplate //添加一个 key ValueOperations value.set("lp", "hello word"); //获取 这个 key 的值 System.out.println(value.get("lp")); //添加 一个 hash集合 HashOperations Map map.put("name","wang.qj"); map.put("age", "30"); hash.putAll("lpMap", map); //获取 map // System.out.println(hash.entries("lpMap")); System.out.println("lpMap-name------"+hash.get("lpMap", "name")); //添加 一个 list 列表 ListOperations list.rightPush("lpList", "lp"); list.rightPush("lpList", "26"); //输出 list System.out.println(list.range("lpList", 0, 1)); //添加 一个 set 集合 SetOperations set.add("lpSet", "lp"); set.add("lpSet", "26"); set.add("lpSet", "178cm"); //输出 set 集合 System.out.println(set.members("lpSet")); //添加有序的 set 集合 ZSetOperations zset.add("lpZset", "lp", 0); zset.add("lpZset", "26", 1); zset.add("lpZset", "178cm", 2); //输出有序 set 集合 System.out.println(zset.rangeByScore("lpZset", 0, 2)); } }RedisTest .java