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

相关推荐
程序员晓琪4 小时前
约定大于配置:基于 Java 包名自动生成 API 版本路由的最佳实践
java·spring boot·后端
Flittly4 小时前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring
用户3521802454751 天前
🎆从 Prompt 到 Skill:让 Spring AI Agent 学会"装新技能"
人工智能·spring boot·ai编程
用户3169353811833 天前
Java连接Redis
redis
用户3521802454754 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
昵称为空C4 天前
手撸一个动态 SQL 执行引擎:不重启服务,在线增删改查任意数据库
spring boot·后端
霸道流氓气质5 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
于先生吖5 天前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解
人工智能·spring boot·后端
小小工匠5 天前
Redis - 事务机制:能实现 ACID 属性吗
数据结构·redis·性能优化·并发·持久化