springboot redis集群怎么实现redis单机

1 添加redis支持
在pom.xml中添加
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-starter-redis&/artifactId&
&/dependency&
2 redis配置
@Configuration
@EnableCaching
public class RedisCacheConfig {
public CacheManager cacheManager(
@SuppressWarnings(&rawtypes&) RedisTemplate redisTemplate) {
return new RedisCacheManager(redisTemplate);
public RedisTemplate&String, String& redisTemplate(
RedisConnectionFactory factory) {
final StringRedisTemplate template = new StringRedisTemplate(factory);
template.setValueSerializer(new Jackson2JsonRedisSerializer&SysUser&(
SysUser.class)); //请注意这里
3 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
*此处的dao操作使用的是spring data jpa,使用@Cacheable可以在任意方法上,*比如@Service或者@Controller的方法上
public interface SysUserRepo1 extends CustomRepository&SysUser, Long& {
@Cacheable(value = &usercache&)
public SysUser findByUsername(String username);
@Controller
public class TestController {
@Autowired
SysUserRepo1 sysUserRepo1;
@RequestMapping(&/test&)
public @ResponseBody String test(){
final SysUser loaded = sysUserRepo1.findByUsername(&wyf&);
final SysUser cached = sysUserRepo1.findByUsername(&wyf&);
return &ok&;
效果如图:
相关 [spring boot redis] 推荐:
- ITeye博客
SysUser.class)); //请注意这里. 3 redis服务器配置. /**
*此处的dao操作使用的是spring data jpa,使用@Cacheable可以在任意方法上,*比如@Service或者@Controller的方法上
public interface SysUserRepo1 extends CustomRepository&SysUser, Long& {.
- 编程语言 - ITeye博客
这次带来的是spring boot + redis 实现session共享的教程. 在spring boot的文档中,告诉我们添加@EnableRedisHttpSession来开启spring session支持,配置如下:. 而@EnableRedisHttpSession这个注解是由spring-session-data-redis提供的,所以在pom.xml文件中添加:
&dependency&.
- 企业架构 - ITeye博客
使用spring boot很方便,一个jar包就可以启动了,因为它里面内嵌了tomcat等服务器. 但是spring boot也提供了部署到独立服务器的方法. 如果你看文档的话,从jar转换为war包很简单,pom.xml的配置修改略去不讲. 只看source的修改,很简单,只要一个配置类,继承自SpringBootServletInitializer, 并覆盖configure方法.
- ImportNew
日,Spring发布了4.0版本. 这个本来只是作为Java平台上的控制反转容器的库,经过将近10年的发展已经成为了一个巨无霸产品. 不过其依靠良好的分层设计,每个功能模块都能保持较好的独立性,是Java平台不可多得的好用的开源应用程序框架. Spring的4.0版本可以说是一个重大的更新,其全面支持Java8,并且对Groovy语言也有良好的支持.
- 廖雪峰的官方网站
使用Spring Boot时,默认情况下,配置
DataSource非常容易. Spring Boot会自动为我们配置好一个
DataSource. 如果在
application.yml中指定了
spring.datasource的相关配置,Spring Boot就会使用该配置创建一个
DataSource.
- ImportNew
spring boot里其实不仅可以直接以 Java -jar demo.jar的方式启动,还可以把jar/war变为一个可以执行的脚本来启动,比如./demo.jar. 把这个executable jar/war 链接到/etc/init.d下面,还可以变为Linux下的一个service. 只要在spring boot maven plugin里配置:.
- ImportNew
在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,不需要另外配置一个Web Server. 如果之前没有使用过spring boot可以通过下面的demo来感受下. 下面以这个工程为例,演示如何启动Spring boot项目:.
- 企业架构 - ITeye博客
实际上在Spring boot里用Spring Security最合适,毕竟是自家东西,最重要的一点是Spring Security里自带有csrf filter,防止csrf攻击,shiro里就没有. 但是Spring Security有点太复杂,custmize起来比较费力,不如shiro来的简单.
- ImportNew
前面两篇博客中我们简单介绍了spring Boot项目的创建、并且也带小伙伴们来DIY了一个Spring Boot自动配置功能,那么这些东西说到底最终还是要回归到Web上才能体现出它的更大的价值,so,今天我们就来看一下如何使用Spring Boot来开发Web项目. 当然,如果小伙伴对Spring Boot尚不熟悉的话,可以先参考一下这两篇博客:.
- ImportNew
Spring MVC异常处理详解 》中,介绍了Spring MVC的异常处理体系,本文将讲解在此基础上Spring Boot为我们做了哪些工作. 下图列出了Spring Boot中跟MVC异常处理相关的类. Spring Boot在启动过程中会根据当前环境进行AutoConfiguration,其中跟MVC错误处理相关的配置内容,在ErrorMvcAutoConfiguration这个类中.
坚持分享优质有趣的原创文章,并保留作者信息和版权声明,任何问题请联系:@。Spring Boot教程(十二)Spring boot集成Redis
Spring Boot教程(十二)Spring boot集成Redis:一.创建项目,项目名称为 &springboot_redis&,创建过程中勾选 &Web&,&Redis&,第一次创建Maven需要下载依赖包(耐心等待)。
properties配置文件中添加配置信息
##########redis############
#redis的IP地址
spring.redis.host=localhost
#redis的端口
spring.redis.port=6379
#redis的密码
spring.redis.password=123456
#redis默认有16个,使用DB0
spring.redis.database=0
创建RedisComponent类
package com.woniu.RedisC
import org.apache.hadoop.mapred.gethistory_;
import org.springframework.beans.factory.annotation.A
import org.springframework.data.redis.core.StringRedisT
import org.springframework.data.redis.core.ValueO
import org.
@Component
public class RedisComponent {
@Autowired
private StringRedisTemplate stringRedisT
public void set(String key, String value){
ValueOperations ops = this.stringRedisTemplate.opsForValue();
boolean bExistent = this.stringRedisTemplate.hasKey(key);
if (bExistent) {
System.out.println(&this key is bExistent!&);
ops.set(key, value);
public String get(String key){
return this.stringRedisTemplate.opsForValue().get(key);
public void del(String key){
this.stringRedisTemplate.delete(key);
创建WebController类
package com.woniu.
import org.springframework.beans.factory.annotation.A
import org.springframework.web.bind.annotation.PathV
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RestC
import com.woniu.RedisComponent.RedisC
@RestController
@RequestMapping(value=&/web&)
public class WebController {
@Autowired
private RedisComponent redisC
@RequestMapping(value=&/set/{key}/{value}&)
public String set(@PathVariable String key, @PathVariable String value){
redisComponet.set(key, value);
return &set key succ!&;
@RequestMapping(value=&/get/{key}&)
public String get(@PathVariable String key){
return redisComponet.get(key);
@RequestMapping(value=&/del/{key}&)
public void del(@PathVariable String key){
redisComponet.del(key);
本机安装redis,设置密码为123456,启动redis。Spring Boot使用redis做数据缓存 -
- ITeye博客
博客分类:
转自:/blog/2184884
1 添加redis支持
在pom.xml中添加
org.springframework.boot
spring-boot-starter-redis
2 redis配置
package com.wisely.ij.
import com.fasterxml.jackson.annotation.JsonAutoD
import com.fasterxml.jackson.annotation.PropertyA
import com.fasterxml.jackson.databind.ObjectM
import org.springframework.cache.CacheM
import org.springframework.cache.annotation.CachingConfigurerS
import org.springframework.cache.annotation.EnableC
import org.springframework.cache.interceptor.KeyG
import org.springframework.context.annotation.B
import org.springframework.context.annotation.C
import org.springframework.data.redis.cache.RedisCacheM
import org.springframework.data.redis.connection.RedisConnectionF
import org.springframework.data.redis.core.RedisT
import org.springframework.data.redis.core.StringRedisT
import org.springframework.data.redis.serializer.Jackson2JsonRedisS
import java.lang.reflect.M
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport{
public KeyGenerator wiselyKeyGenerator(){
return new KeyGenerator() {
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
return sb.toString();
public CacheManager cacheManager(
@SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {
return new RedisCacheManager(redisTemplate);
public RedisTemplate&String, String& redisTemplate(
RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
3 redis服务器配置
Properties代码
# 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
测试两个实体类
package com.wisely.ij.
public class Address {
public Address(Long id,String province, String city) {
this.province =
this.city =
public Address() {
public Long getId() {
public void setId(Long id) {
public String getProvince() {
public void setProvince(String province) {
this.province =
public String getCity() {
public void setCity(String city) {
this.city =
package com.wisely.ij.
public class User {
private String firstN
private String lastN
public User(Long id,String firstName, String lastName) {
this.firstName = firstN
this.lastName = lastN
public User() {
public Long getId() {
public void setId(Long id) {
public String getFirstName() {
return firstN
public void setFirstName(String firstName) {
this.firstName = firstN
public String getLastName() {
return lastN
public void setLastName(String lastName) {
this.lastName = lastN
package com.wisely.ij.
import com.wisely.ij.domain.A
import com.wisely.ij.domain.U
import org.springframework.cache.annotation.C
import org.springframework.stereotype.S
public class DemoService {
@Cacheable(value = "usercache",keyGenerator = "wiselyKeyGenerator")
public User findUser(Long id,String firstName,String lastName){
System.out.println("无缓存的时候调用这里");
return new User(id,firstName,lastName);
@Cacheable(value = "addresscache",keyGenerator = "wiselyKeyGenerator")
public Address findAddress(Long id,String province,String city){
System.out.println("无缓存的时候调用这里");
return new Address(id,province,city);
package com.wisely.ij.
import com.wisely.ij.domain.A
import com.wisely.ij.domain.U
import com.wisely.ij.service.DemoS
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.C
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.ResponseB
@Controller
public class DemoController {
@Autowired
DemoService demoS
@RequestMapping("/test")
@ResponseBody
public String putCache(){
demoService.findUser(1l,"wang","yunfei");
demoService.findAddress(1l,"anhui","hefei");
System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功");
return "ok";
@RequestMapping("/test2")
@ResponseBody
public String testCache(){
User user = demoService.findUser(1l,"wang","yunfei");
Address address =demoService.findAddress(1l,"anhui","hefei");
System.out.println("我这里没执行查询");
System.out.println("user:"+"/"+user.getFirstName()+"/"+user.getLastName());
System.out.println("address:"+"/"+address.getProvince()+"/"+address.getCity());
return "ok";
先访问http://localhost:8080/test 保存缓存
再访问http://localhost:8080/test2 调用缓存里的数据
fanfeiyang
浏览: 1035 次
来自: 广州org.springframework.boot
spring-boot-starter
org.springframework
spring-context-support
4.3.5.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.session
spring-session-data-redis
org.springframework.boot
spring-boot-starter-redis
1.3.8.RELEASE
org.springframework.boot
spring-boot-starter-test
org.springframework.data
spring-data-redis
org.springframework.boot
spring-boot-maven-plugin
5.新建Controller类DemoController.java
@Controller
public class DemoController {
@Autowired
DemoService demoS
@RequestMapping("testcache")
@ResponseBody
public String testCache(@RequestParam String key){
String s = demoService.testCache(key);
@RequestMapping("/getseansession")
@ResponseBody
public Map getSession(HttpServletRequest request){
Map attributeMap = new HashMap();
request.getSession().setAttribute("message", request.getRequestURI());
attributeMap.put("message", request.getRequestURI());
System.out.println("sessionID:" + request.getSession().getId());
return attributeM
6.新建Service类DemoService.java
public class DemoService {
@Cacheable(value = "keycache")
public String testCache(String key){
System.out.println("testCache:" + key);
7.新建RedisConfig类增加@EnableRedisHttpSession注解
@Configuration
@EnableCaching
@EnableRedisHttpSession
public class RedisConfig{
8.application.properties文件配置,其中为了测试ngnix负载均衡功能,本工程配置为8080端口,另一个springboot工程可以配置为别的端口,比如8088,以便启动两个Server
#redis spring.redis.password=xxx
#spring.redis.database= # database name
spring.redis.hostname=127.0.0.1 # server host
spring.redis.port=6379
spring.redis.pool.maxActive=8
spring.redis.pool.maxWait=-1
spring.redis.pool.maxIdle=8
spring.redis.pool.minIdle=0
spring.redis.timeout=0
#tomcat port configuration
server.port=8080
可以看到启动了两个Server,DemoApplication和DemoApplication(1)
9.ngnix.conf配置文件中配置负载均衡策略
upstream test {
server localhost:8080;
server localhost:8088;
client_max_body_size 1024M;
#charset koi8-r;
#access_log
logs/host.access.
#location / {
index.html index.
location / {
proxy_pass http://test/
proxy_set_header Host $host:$server_
10.访问http://localhost,会发现http请求交替访问后端两个server。且sessionID是一样的“sessionID:ad0cbb3b-d24d-4d61-87ac-b9ddcfeccaa4”。并没有因为server不一致而sessionID不同
使用RedisClient连接Redis Server,确实存储了一个sessionID,如下:
11.maven工程目录
12.实际操纵过程中遇到一个问题:启动springboot工程的时候报错“java.lang.IllegalStateException: Cannot load configuration class: org.springframework.boot.autoconfigure.cache.RedisCacheConfiguration”
解决方法:对于spring-context-support依赖,增加了一个version,且版本为4.3.5.RELEASE。启动,未报错,问题解决。没配version的时候,默认是4.3.6.RELEASE,奇怪。后续有时间再研究。
org.springframework
spring-context-support
4.3.5.RELEASE
以上就是对SpringBoot+Redis+Nginx实现负载均衡以及Session缓存共享的相关介绍,希望对您学习java有所帮助,感谢您关注织梦者!
这些内容可能对你也有帮助
更多可查看Java编程列表页。
猜您也会喜欢这些文章19977人阅读
spring boot(6)
java学习资料(2)
通过上面一些笔记的介绍,
我们可以自己动手去集成Redis, 没有什么难度的
还有Spring Boot官方提供了Spring-Data-Redis的Starter POM
有兴趣的可以查看下这篇资料
手动集成Redis
&project xmlns=&http://maven.apache.org/POM/4.0.0& xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&
xsi:schemaLocation=&http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&&
&modelVersion&4.0.0&/modelVersion&
&groupId&com.ibigsea&/groupId&
&artifactId&springboot-redis-demo&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&properties&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&boot.version&1.3.5.RELEASE&/boot.version&
&/properties&
&dependencies&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-starter-web&/artifactId&
&version&${boot.version}&/version&
&/dependency&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-starter-test&/artifactId&
&version&${boot.version}&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&redis.clients&/groupId&
&artifactId&jedis&/artifactId&
&version&2.8.2&/version&
&/dependency&
&/dependencies&
&/project&
整个项目的结构图是这样的
RedisConfiguration.java
package com.ibigsea.springboot_redis_demo.
import org.springframework.beans.factory.annotation.A
import org.springframework.beans.factory.annotation.Q
import org.springframework.beans.factory.annotation.V
import org.springframework.context.annotation.B
import org.springframework.context.annotation.C
import redis.clients.jedis.JedisP
import redis.clients.jedis.JedisPoolC
@Configuration
public class RedisConfiguration {
@Bean(name= &jedis.pool&)
@Autowired
public JedisPool jedisPool(@Qualifier(&jedis.pool.config&) JedisPoolConfig config,
@Value(&${jedis.pool.host}&)String host,
@Value(&${jedis.pool.port}&)int port) {
return new JedisPool(config, host, port);
@Bean(name= &jedis.pool.config&)
public JedisPoolConfig jedisPoolConfig (@Value(&${jedis.pool.config.maxTotal}&)int maxTotal,
@Value(&${jedis.pool.config.maxIdle}&)int maxIdle,
@Value(&${jedis.pool.config.maxWaitMillis}&)int maxWaitMillis) {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(maxTotal);
config.setMaxIdle(maxIdle);
config.setMaxWaitMillis(maxWaitMillis);
RedisClient.java
package com.ibigsea.springboot_redis_demo.
import org.springframework.beans.factory.annotation.A
import org.
import redis.clients.jedis.J
import redis.clients.jedis.JedisP
* 就一个小Demo 随便写下
* @author bigsea
@Component
public class RedisClient {
@Autowired
private JedisPool jedisP
public void set(String key, String value) throws Exception {
Jedis jedis =
jedis = jedisPool.getResource();
jedis.set(key, value);
} finally {
//返还到连接池
jedis.close();
public String get(String key) throws Exception
Jedis jedis =
jedis = jedisPool.getResource();
return jedis.get(key);
} finally {
//返还到连接池
jedis.close();
package com.ibigsea.springboot_redis_
import org.springframework.beans.factory.annotation.A
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RestC
import com.ibigsea.springboot_redis_demo.config.RedisC
* 是Spring Boot项目的核心注解,主要是开启自动配置
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
@RestController
public class App {
@Autowired
private RedisClient redisC
public static void main(String[] args) {
SpringApplication.run(App.class, args);
@RequestMapping(&/set&)
public String set(String key, String value) throws Exception{
redisClinet.set(key, value);
return &success&;
@RequestMapping(&/get&)
public String get(String key) throws Exception {
return redisClinet.get(key);
application.yml
host : 127.0.0.1
port : 6379
maxTotal: 100
maxIdle: 10
maxWaitMillis : 100000
port : 8082
实现自己的jedis-spring-boot-starter
一些自动配置的东西这里面有讲
首先我们创建一个jedis-spring-boot-starter
&project xmlns=&http://maven.apache.org/POM/4.0.0& xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&
xsi:schemaLocation=&http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&&
&modelVersion&4.0.0&/modelVersion&
&groupId&com.ibigsea&/groupId&
&artifactId&jedis-spring-boot-starter&/artifactId&
&version&1.0-SNAPSHOT&/version&
&properties&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&boot.version&1.3.5.RELEASE&/boot.version&
&/properties&
&dependencies&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot&/artifactId&
&version&${boot.version}&/version&
&/dependency&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-autoconfigure&/artifactId&
&version&${boot.version}&/version&
&/dependency&
&dependency&
&groupId&redis.clients&/groupId&
&artifactId&jedis&/artifactId&
&version&2.8.2&/version&
&/dependency&
&/dependencies&
&/project&
目录结构是这样的
JedisProperties.java
package com.ibigsea.jedis.
import org.springframework.boot.context.properties.ConfigurationP
@ConfigurationProperties(prefix = JedisProperties.JEDIS_PREFIX)
public class JedisProperties {
public static final String JEDIS_PREFIX = &jedis&;
private int maxT
private int maxI
private int maxWaitM
public String getHost() {
public void setHost(String host) {
this.host =
public int getPort() {
public void setPort(int port) {
this.port =
public int getMaxTotal() {
return maxT
public void setMaxTotal(int maxTotal) {
this.maxTotal = maxT
public int getMaxIdle() {
return maxI
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxI
public int getMaxWaitMillis() {
return maxWaitM
public void setMaxWaitMillis(int maxWaitMillis) {
this.maxWaitMillis = maxWaitM
JedisAutoConfiguration.java
package com.ibigsea.jedis.
import org.springframework.beans.factory.annotation.A
import org.springframework.beans.factory.annotation.Q
import org.springframework.boot.autoconfigure.condition.ConditionalOnC
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingB
import org.springframework.boot.context.properties.EnableConfigurationP
import org.springframework.context.annotation.B
import org.springframework.context.annotation.C
import com.ibigsea.jedis.client.RedisC
import redis.clients.jedis.JedisP
import redis.clients.jedis.JedisPoolC
@Configuration
@EnableConfigurationProperties(JedisProperties.class)//开启属性注入,通过@autowired注入
@ConditionalOnClass(RedisClient.class)//判断这个类是否在classpath中存在
public class JedisAutoConfiguration {
@Autowired
private JedisP
@Bean(name=&jedisPool&)
public JedisPool jedisPool() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(prop.getMaxTotal());
config.setMaxIdle(prop.getMaxIdle());
config.setMaxWaitMillis(prop.getMaxWaitMillis());
return new JedisPool(config, prop.getHost(), prop.getPort());
@ConditionalOnMissingBean(RedisClient.class)//容器中如果没有RedisClient这个类,那么自动配置这个RedisClient
public RedisClient redisClient(@Qualifier(&jedisPool&)JedisPool pool) {
RedisClient redisClient = new RedisClient();
redisClient.setJedisPool(pool);
return redisC
RedisClient.java
package com.ibigsea.jedis.
import redis.clients.jedis.J
import redis.clients.jedis.JedisP
* 就一个小Demo 随便写下
* @author bigsea
public class RedisClient {
private JedisPool jedisP
public void set(String key, String value) throws Exception {
Jedis jedis =
jedis = jedisPool.getResource();
jedis.set(key, value);
} finally {
//返还到连接池
jedis.close();
public String get(String key) throws Exception
Jedis jedis =
jedis = jedisPool.getResource();
return jedis.get(key);
} finally {
//返还到连接池
jedis.close();
public JedisPool getJedisPool() {
return jedisP
public void setJedisPool(JedisPool jedisPool) {
this.jedisPool = jedisP
还要在spring.factories里面配置
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.ibigsea.jedis.autoconfigure.JedisAutoConfiguration
新建一个工程测试下
&project xmlns=&http://maven.apache.org/POM/4.0.0& xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&
xsi:schemaLocation=&http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&&
&modelVersion&4.0.0&/modelVersion&
&groupId&com.ibigsea&/groupId&
&artifactId&test-starter&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&packaging&jar&/packaging&
&name&test-starter&/name&
&url&http://maven.apache.org&/url&
&properties&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&boot.version&1.3.5.RELEASE&/boot.version&
&/properties&
&dependencies&
&dependency&
&groupId&com.ibigsea&/groupId&
&artifactId&jedis-spring-boot-starter&/artifactId&
&version&1.0-SNAPSHOT&/version&
&/dependency&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-starter-web&/artifactId&
&version&${boot.version}&/version&
&/dependency&
&dependency&
&groupId&org.springframework.boot&/groupId&
&artifactId&spring-boot-starter-test&/artifactId&
&version&${boot.version}&/version&
&scope&test&/scope&
&/dependency&
&/dependencies&
&/project&
application.yml
host : 127.0.0.1
port : 6379
maxTotal: 100
maxIdle: 10
maxWaitMillis : 100000
port : 8082
package com.ibigsea.test_
import org.springframework.beans.factory.annotation.A
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RestC
import com.ibigsea.jedis.client.RedisC
@SpringBootApplication
@RestController
public class App {
@Autowired
private RedisClient redisC
public static void main(String[] args) {
SpringApplication.run(App.class, args);
@RequestMapping(&/set&)
public String set(String key, String value) throws Exception{
redisClient.set(key, value);
return &success&;
@RequestMapping(&/get&)
public String get(String key) throws Exception {
return redisClient.get(key);
这里只是简单的写了下一个小demo,有兴趣的小伙伴可以自己去扩展更多的
比如实现集群连接, 分片连接,API扩展的更多一些
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:236175次
积分:2620
积分:2620
排名:第13753名
原创:55篇
评论:120条
(1)(1)(2)(4)(1)(5)(4)(12)(2)(4)(5)(19)}

我要回帖

更多关于 springboot redis实例 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信