码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • springboot集成Redis


    目录

    1、环境

    2、工程目录

    3、主要代码

    4、启动Redis

    5、执行结果

    6、完整代码


    1、环境

    IDE:IDEA2020

    JDK:JDK8

    redis_version:3.2.100

     2、工程目录

    3、主要代码

    (1)pom文件

    1. "1.0" encoding="UTF-8"?>
    2. "http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. 4.0.0
    6. org.example
    7. 01-springboot
    8. pom
    9. 1.0-SNAPSHOT
    10. org.springframework.boot
    11. spring-boot-starter-parent
    12. 2.1.8.RELEASE
    13. org.springframework.boot
    14. spring-boot-starter-data-redis
    15. org.springframework.boot
    16. spring-boot-starter-test
    17. test
    18. org.springframework.boot
    19. spring-boot-maven-plugin

    (2)测试代码

    1. package com.springboot.redis;
    2. import org.junit.Test;
    3. import org.junit.runner.RunWith;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.boot.test.context.SpringBootTest;
    6. import org.springframework.data.redis.core.RedisTemplate;
    7. import org.springframework.test.context.junit4.SpringRunner;
    8. @RunWith(SpringRunner.class)
    9. @SpringBootTest
    10. public class SpringbootRedisApplicationTests {
    11. @Autowired
    12. private RedisTemplate redisTemplate;
    13. @Test
    14. public void testSet(){
    15. //存入数据
    16. redisTemplate.boundValueOps("name").set("zhangsan");
    17. }
    18. @Test
    19. public void testGet(){
    20. //获取数据
    21. Object name = redisTemplate.boundValueOps("name").get();
    22. System.out.println(name);
    23. }
    24. }

    (3)配置文件

    1. spring:
    2. redis:
    3. host: 127.0.0.1
    4. port: 6379

    (4)引导类

    1. package com.springboot.redis;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. @SpringBootApplication
    5. public class SpringbootRedisApplication {
    6. public static void main(String[] args) {
    7. SpringApplication.run(SpringbootRedisApplication.class, args);
    8. }
    9. }

    4、启动Redis

     

     5、执行结果

    6、完整代码

    链接:https://pan.baidu.com/s/1dhTVjf7_yIAn52tSMd72Sw
    提取码:8xxi

     

  • 相关阅读:
    Redis入门到通关之Redis数据结构-List篇
    CUDA编程- 矩阵乘法
    企业知识库软件,快速构建企业知识分享与团队协同的软件
    说说 MVCC 的工作原理?
    鸿蒙HarmonyOS实战-ArkUI组件(Navigation)
    一次 Redis 事务使用不当引发的生产事故
    VEP Variant Effect Predictor支持哪些输入格式
    IDEA的乱码与file.encoding = UTF-8
    gendef和pexports
    LeetCode 0107.二叉树的层序遍历II - 另一种方法
  • 原文地址:https://blog.csdn.net/weibo1230123/article/details/126109858
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号