首页 > 编程语言 > 详细

springboot系列十、springboot整合redis

时间:2018-12-29 13:24:35      阅读:146      评论:0      收藏:0      [点我收藏+]

一、简介

Redis 的数据库的整合在 java 里面提供的官方工具包:jedis,所以即便你现在使用的是 SpringBoot,那么也继续使用此开发包。

二、redidTemplate操作

在 Spring 支持的 Redis 操作之中提供有一个 RedisTemplate 处理程序类,利用这个类可以非常方便的实现 Redis 的各种基本数 据操作。

1、引入依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2、配置yml

spring:  
  redis:
    host: 47.52.199.52
    port: 6379
    password: 123456
    timeout: 1000
    database: 0
    jedis:
      pool:
        max-active: 4
        max-idle: 8
        min-idle: 2
        max-wait: 100

3、使用示例

@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class DemoApplicationTests {

@Resource
private RedisTemplate<String, String> redisTemplate; @Test public void testRedis(){ redisTemplate.opsForValue().set("xing","12345678"); System.out.println(redisTemplate.opsForValue().get("xing")); } }

 

springboot系列十、springboot整合redis

原文:https://www.cnblogs.com/wangzhuxing/p/10195198.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!