码农知识堂 - 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

     

  • 相关阅读:
    B树和B+树的区别
    Azure + React + ASP.NET Core 项目笔记一:项目环境搭建(一)
    软件为什么单独标注支持IPV6?IPV6和IPV4有什么区别?
    x210项目重新回顾之十七升级到linux4.19.114 +buildroot2018再讨论
    Win11系统怎么安装到虚拟机的方法分享
    C#宏定义
    跑一跑NeuralAnnot
    腾讯云服务器新用户优惠活动有哪些?腾讯云新用户优惠活动汇总
    Halcon xld镜像操作
    Wireshark 用命令行分析数据包
  • 原文地址:https://blog.csdn.net/weibo1230123/article/details/126109858
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号