redis在spring框架中的使用
来源:互联网 发布:测量图片尺寸软件 编辑:程序博客网 时间:2024/04/30 16:34
redis的客户端实现我选择的是jedis
spring框架中包含了对redis的支持,其实是一层封装,使得我们可以使用样板来简化代码,也可以选择不使用spring提供的样板,自己在jedis基础上做封装
使用spring的项目可以很容易就将redis功能添加进来,作为系统的缓存
redis服务端是单独部署的,spring中配置的是redis的客户端,使得spring项目可以访问到redis服务器
首先是包的引入,
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency>
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.0.2.RELEASE</version> </dependency>
spring的部分配置,不同的jedis版本,参数也发生了变化,尤其需要注意根据不同的版本使用对应的参数命名
<context:property-placeholder location="classpath:redis.properties" /> <context:component-scan base-package="com.x.redis.dao"> </context:component-scan> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxActive" value="${redis.maxActive}" /> <property name="maxWait" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> </bean>
最后一个bean redisTemplate
通过注入的方式在程序中使用
@Autowiredprotected RedisTemplate<Serializable, Serializable> redisTemplate;
0 0
- redis在spring框架中的使用
- redis在spring中的使用
- redis在spring中的配置
- Spring Boot 中的redis使用
- Quartz在真实项目中的使用(结合Spring框架)
- AOP编程简介及其在Spring框架中的使用
- redis中的基本数据类型,以及在Spring-Boot对Redis的基本使用
- redis中的基本数据类型,以及在Spring-Boot对Redis的基本使用
- 1 redis在spring中的配置及java代码实现 2 redis在java项目中的使用
- Redis 在 Java 中的使用
- redis在shell中的使用
- Redis在YiiFramework中的使用
- Redis在Java中的使用
- redis在项目中的使用
- redis在java中的使用
- redis在项目中的使用
- Redis-在.NET中的使用
- redis在程序中的使用
- 等待超时模式在数据库连接池中的使用
- 使用深度学习打造智能聊天机器人
- oracle实例管理及数据库的启动/关闭
- 开源软件架构 - Asterisk
- Leetcode 94. Binary Tree Inorder Traversal
- redis在spring框架中的使用
- JavaScript强化教程——Native.js示例汇总
- Android总结
- 最新县及县以上行政区划代码 的数据进行分割 对应的成一级二级 然后对写进数据库就容易了
- 开源软件架构-GDB
- 专题四1011
- mysql的主、从、dump数据库关系
- 抽象类与接口及简单的工厂模式
- svn常见问题,报错,命令