spring-boot-starter-redis 集成
来源:互联网 发布:java动态数组 编辑:程序博客网 时间:2024/04/23 21:16
redis支持
代码块
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-redis --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> <version>1.0.1.RELEASE</version></dependency>
更多支持
http://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-redis
redis配置
# REDIS (RedisProperties) spring.redis.database= # database name spring.redis.host=localhost # server host spring.redis.password= # server password spring.redis.port=6379 # connection port spring.redis.pool.max-idle=8 # pool settings ... spring.redis.pool.min-idle=0 spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1 spring.redis.sentinel.master= # name of Redis server spring.redis.sentinel.nodes= # comma-separated list of host:port pairs
JAVA代码
package com.pay.channel.business;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.connection.RedisConnection;import org.springframework.data.redis.connection.RedisConnectionFactory;import org.springframework.stereotype.Component;/** * redis * com.pay.channel.business.RedisBusiness * * @email h_anke@163.com * @create 2017-03-06 13:57 **/@Componentpublic class RedisBusiness { private static final Logger logger = LoggerFactory.getLogger(RedisBusiness.class); @Autowired private RedisConnectionFactory redisConnectionFactory; public void setEx(String key, String value , int expire) throws Exception{ RedisConnection connection = redisConnectionFactory.getConnection(); try { connection.setEx(key.getBytes(), expire, value.getBytes()); }catch (Exception e){ logger.warn("redis 保存数据出现情况,现发起一次重复连接", e); if (connection != null) connection.close(); connection = redisConnectionFactory.getConnection(); connection.setEx(key.getBytes(), expire, value.getBytes()); }finally { if (connection != null) connection.close(); } } public void del(String key) throws Exception{ RedisConnection connection = redisConnectionFactory.getConnection(); try { connection.del(key.getBytes()); } finally { if (connection != null) connection.close(); } } public String get(String key) throws Exception{ RedisConnection connection = redisConnectionFactory.getConnection(); byte[] bytes = null; try { bytes = connection.get(key.getBytes()); }finally { if (connection != null) connection.close(); } if (bytes == null) { logger.warn("redis缓存无此key,可能是超时失效了"); throw new Exception("redis 失效"); } return new String(bytes); } public void set(String key,String value) throws Exception{ RedisConnection connection = redisConnectionFactory.getConnection(); try { connection.set(key.getBytes(), value.getBytes()); }finally { if (connection != null) connection.close(); } }}
18 0
- spring-boot-starter-redis 集成
- spring-boot-starter-redis 集成
- spring-boot-starter-data-redis
- Spring Boot 44个Starter集成包
- spring-boot-starter-redis学习笔记
- spring-boot-starter-redis配置详解
- Spring Boot Redis 集成
- Spring Boot集成Redis
- spring-boot 集成 redis
- spring boot 集成redis
- Spring boot集成Redis
- Spring Boot 集成Redis
- spring boot集成redis
- spring-boot集成swagger( 提供封装的starter源码)
- spring boot starter 详解
- spring boot自定义starter
- spring-boot-starter-dubbo
- spring-boot-starter-security
- 使用Springmvc出现问题及解决办法
- 与现有异步源桥接
- 有权图的最短路径算法——Dijkstra算法
- 详解spring事务属性(传播行为,事务的隔离级别)
- C++标准转换运算符reinterpret_cast
- spring-boot-starter-redis 集成
- Handler系列之原理分析
- 【教你抢课】C++网络编程之使用Winsock2实现教务系统自动抢课程序
- Linux下NC扫描TCP,UDP端口
- head first 设计模式之---------装饰者模式
- Android 蓝牙技术 实现终端间数据传输
- Android可折叠的textview
- VersionCompare
- golang 操作mysql的CRUD