SpringBoot初步连接redis详解
2017-12-20 10:05
519 查看
在初次用springboot连接redis的时候查看官方文档和一些博客会发现配置文件非常的多,这就导致了在学习的开始的时候是没有体验的,其实利用springboot连接redis的时候并不需要那么多的配置
首先开启redis服务器:
然后在springboot里面添加配置文件:
# Redis数据库索引(默认为0) spring.redis.database=0 # Redis服务器地址 spring.redis.host=localhost # Redis服务器连接端口 spring.redis.port=6379 # Redis服务器连接密码(默认为空) spring.redis.password= # 连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1 # 连接池中的最大空闲连接 spring.redis.pool.max-idle=8 # 连接池中的最小空闲连接 spring.redis.pool.min-idle=0 # 连接超时时间(毫秒) spring.redis.timeout=0
最后在springboot的pom.xml文件中添加依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
然后在springboot的项目中写一个测试类:
@RunWith(SpringRunner.class) @SpringBootTest public class ShoppingApplicationTests { @Autowired private StringRedisTemplate stringRedisTemplate; @Test public void test() throws Exception { List<String> list =new ArrayList<>(); list.add("a"); list.add("b"); list.add("v"); stringRedisTemplate.opsForValue().set("abc", "测试"); stringRedisTemplate.opsForList().leftPushAll("qq",list); // 向redis存入List stringRedisTemplate.opsForList().range("qwe",0,-1).forEach(value ->{ System.out.println(value); } ); }
然后在redis里面便可以看到了刚才的新建的
然后这就是最简单的springboot连接redis的方式了
总结
以上就是本文关于SpringBoot初步连接redis详解的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:
如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- springboot集成redis详解
- redis命令详解与使用场景举例——Connection(连接)
- springboot连接redis密码验证失败
- PHP使用Redis长连接的方法详解
- 详解springboot配置多个redis连接
- 详解Redis开启远程登录连接
- Python连接Redis配置详解
- SpringBoot开发详解(十一) -- Redis在SpringBoot中的整合
- 详解SpringBoot集成Redis来实现缓存技术方案
- Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis
- 连接redis数据库 详解 (jedis工具类封装讲解特别好)
- springboot配置多个redis连接
- springboot连接redis并动态切换database
- 【Redis缓存机制】详解Java连接Redis_Jedis_事务
- redis——数据类型详解
- 详解Spring boot使用Redis集群替换mybatis二级缓存
- redis的安装(图文详解)
- DUnit初步学习及TTestCase中的方法详解
- TCP连接与断开详解(socket通信)
- ld命令_Linux ld 命令用法详解:将目标文件连接为可执行程序