Spring boot整合接入Redis

Spring boot简单接入Redis

1.pom文件中引入redis

XML 复制代码
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

2.yml文件redis属性配置

XML 复制代码
spring:
  redis:
    host: 120.46.40.0
    port: 6379

redis在搭建时没有设置账号密码, 所以不需要配置

3.测试类进行添加数据测试

java 复制代码
@Resource
    private StringRedisTemplate stringRedisTemplate;

    @Test
    void redisTest() {

        ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
        stringStringValueOperations.set("zj","zjj");
        String zj = stringStringValueOperations.get("zj");
        System.out.printf("数据="+zj);

    }

4.测试结果

相关推荐
ShineWinsu3 小时前
对于Redis:主从复制的解析
linux·数据库·c++·redis·缓存·面试·主从复制
vx-程序开发5 小时前
【计算机毕设】51300童装超市管理系统的设计与实现
java·vue.js·spring boot·源码·课程设计·毕设·大作业
ym hyd 1116 小时前
题库建立与考试系统源码 Java+SpringBoot+Vue3 前后分离
java·开发语言·vue.js·spring boot·毕设
ShineWinsu6 小时前
对于Redis:事务的解析
数据库·redis·mysql·缓存·面试·事务·acid
萧瑟余晖7 小时前
Spring Boot Starter机制与自定义详解
spring boot
夕除8 小时前
redis--OpenResty
java·redis
vx-程序开发8 小时前
【计算机毕设】52744基于微信小程序的民宿智能预订系统
java·spring boot·毕业设计·源码·课程设计·毕设·大作业
萧瑟余晖8 小时前
Spring Boot 配置体系详解
spring boot
专业程序开发源9 小时前
springboot古城景区管理系统88564-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·spring·php·课程设计
小蒜学长9 小时前
基于微信小程序的遇见咖啡店点餐系统设计与实现(代码+数据库+LW)
java·spring boot·后端·微信小程序·咖啡店点餐系统