Redisson是redis一个很强大的客户端,有兴趣的同学可以看我的下一篇文章,这篇主要讲如何整合,费话不多说,直接上干货(大牛请绕道)
首先创建RedissionConfig文件
import org.redisson.Redisson;import org.redisson.api.RedissonClient;import org.redisson.config.Config;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.data.redis.RedisProperties;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;/** * author:yuxuan * date:2018/12/16/016 11:42 * description */@Configurationpublic class RedissonConfig { @Autowired private RedisProperties redisProperties; @Bean public RedissonClient redissonClient(){ Config config = new Config(); String redisUrl = String.format("redis://%s:%s",redisProperties.getHost()+"",redisProperties.getPort()+""); config.useSingleServer().setAddress(redisUrl).setPassword(redisProperties.getPassword()); config.useSingleServer().setDatabase(3); return Redisson.create(config); }}
在application.properties配置如下:
spring.redis.host=127.0.0.0spring.redis.port=6378spring.redis.database=0spring.redis.password=
pom.xml引入:
org.springframework.boot spring-boot-starter-data-redis org.redisson redisson 3.8.2