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.测试结果

相关推荐
f***147721 分钟前
SpringBoot实战:高效实现API限流策略
java·spring boot·后端
计算机毕设VX:Fegn089522 分钟前
计算机毕业设计|基于springboot + vue动物园管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
BD_Marathon1 小时前
SpringBoot——多环境开发配置
java·spring boot·后端
至善迎风2 小时前
Redis完全指南:从诞生到实战
数据库·redis·缓存
QQ_4376643144 小时前
Redis协议与异步方式
数据库·redis·bootstrap
BD_Marathon5 小时前
配置文件分类
spring boot
M***Z2105 小时前
springboot中配置logback-spring.xml
spring boot·spring·logback
fengbizhe5 小时前
bootstrapTable转DataTables,并给有着tfoot的DataTables加滚动条
javascript·bootstrap
f***28145 小时前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins
oMcLin5 小时前
如何在 Debian 10 上配置并优化 Redis 集群,确保低延迟高并发的实时数据缓存与查询
redis·缓存·debian