redisTemplate 总结
jackson
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.4</version>
</dependency>
spring-data-redis
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.4.RELEASE</version>
</dependency>
<!--配置redisTemplate-->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="127.0.0.1"></property>
<property name="port" value="6379"/>
<property name="usePool" value="true"></property>
<property name="poolConfig" ref="poolConfig"></property>
</bean> <!-- redies start -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 省略心跳包设置 -->
</bean>
<!--bean可以配置RedisTemplate 也可以配置StringRedisTemplate-->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="stringSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
</bean>
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向redis里存入数据和设置缓存时间 stringRedisTemplate.boundValueOps("test").increment(-1);//val做-1操作 stringRedisTemplate.opsForValue().get("test")//根据key获取缓存中的val stringRedisTemplate.boundValueOps("test").increment(1);//val +1 stringRedisTemplate.getExpire("test")//根据key获取过期时间 stringRedisTemplate.getExpire("test",TimeUnit.SECONDS)//根据key获取过期时间并换算成指定单位 stringRedisTemplate.delete("test");//根据key删除缓存 stringRedisTemplate.hasKey("546545");//检查key是否存在,返回boolean值 stringRedisTemplate.opsForSet().add("red_123", "1","2","3");//向指定key中存放set集合 stringRedisTemplate.expire("red_123",1000 , TimeUnit.MILLISECONDS);//设置过期时间 stringRedisTemplate.opsForSet().isMember("red_123", "1")//根据key查看集合中是否存在指定数据 stringRedisTemplate.opsForSet().members("red_123");//根据key获取set集合
```
StringRedisTemplate的使用
使用注解@Autowired 即可
redisTemplate 总结的更多相关文章
- redisTemplate的spring配置以及lua脚本驱动
最近在使用spring-data-redis的redisTemplate,所以写篇使用记录吧. 1.不用多说,使用maven引入相关依赖,因为项目已经引入其他的 <dependency> ...
- 使用RedisTemplate进行Redis存取的工具类设计
通常在访问量大数据更新频率不高的系统中会使用第三方的缓存组件来降低数据库服务的负载,鉴于模块独立分工独立的考虑,针对缓存组件操作的工作全部应该统一接口对其他业务提供服务,这样业务操作只需要关注业务实现 ...
- spring data redis RedisTemplate操作redis相关用法
http://blog.mkfree.com/posts/515835d1975a30cc561dc35d spring-data-redis API:http://docs.spring.io/sp ...
- Maven中Spring-Data-Redis存储对象(redisTemplate)
Redis是一种nosql数据库,在开发中常用做缓存.Jedis是Redis在java中的redis- client.在此之前,希望已经了解redis的基本使用和Maven的使用.建立Maven Pr ...
- 使用RedisTemplate的操作类访问Redis(转)
深入理解Spring Redis的使用 (三).使用RedisTemplate的操作类访问Redis 事务需要开启enableTransactionSupport,然后使用@transactional ...
- spring mvc Spring Data Redis RedisTemplate [转]
http://maven.springframework.org/release/org/springframework/data/spring-data-redis/(spring-data包下载) ...
- Spring Data Redis简介以及项目Demo,RedisTemplate和 Serializer详解
一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis, ...
- RedisTemplate
Spring Boot中Jedis几个api返回值的确认 @RequestMapping("/del/{key}") public String del(@PathVariable ...
- 深入理解Spring Redis的使用 (二)、RedisTemplate事务支持、序列化
RedisTemplate api详解 1. RedisTemplate的事务 private boolean enableTransactionSupport = false; private bo ...
- RedisTemplate.htm
http://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/core/RedisTe ...
随机推荐
- SVN教程 -- 基于自己学习记录
SVN教程 -- 基于自己学习记录 1. 概述 a. 什么是SVN? Apache Subversion 通常被缩写成 SVN,是一个开放源代码的版本控制系统.相较于 git ,svn 是集中式版本控 ...
- IE下判断IE版本的语句...[if lte IE 6]……[endif](用户判断IE版本的如果小于6就显示)
<!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![endif]--> ...
- leetcode-73-矩阵置零
题目描述: 给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [ [1,1,1], [1,0,1], [1, ...
- 前端知识总结--js原型链
js的原型链听着比较深奥,看着容易晕,梳理一下还是比较容易懂的 (先简单写下,后续有时间再整理) 简而言之 原型链:就是js的对象与对象之间,通过原型组成建立的层层关系,构成了整个链条,称之为原型链 ...
- 第三方库PIL
第三方库PIL 一.Python简介 Python是一门简洁高效.通俗易懂的高阶动态编程语言,也可以理解成是一种面向对象的解释型计算机程序设计语言. Python具有丰富和强大的库.也经常被行内人员称 ...
- 一款开源免费的办公套件系统:DzzOffice详细部署
一.系统环境 个人建议centos 7 系统 cat /etc/redhat-release CentOS Linux release (Core) 基本更新 yum update -y 基本优化 关 ...
- anyncTask的3个参数(从源码可以发现其中使用了ThreadPoolExcuter线程池)
AnyncTask异步处理数据并将数据应用到视图的操作场合 一 其中包含这几个方法 1 onPreExcute() 初始化控件,例如进度条2 doInBackground() 具体的执行动作请求数据 ...
- wap webapp app区别
“手机WAP版网站”.“手机触屏版网站”.“手机APP应用软件”: wap webapp app区别 电脑版:台式机或者笔记本访问,兼容各个浏览器: Wap版:用于传统智能手机,屏幕小,适合使用手机键 ...
- the unchecked warnings
5.1.9. Unchecked Conversion Let G name a generic type declaration with n type parameters. There is a ...
- Gradle中的SourceSet理解
对于maven项目来说,目录结构是固定的,也就是像这样: src/main/ src/main/java/ src/main/resources/ src/test/ src/test/java/ s ...