zoukankan      html  css  js  c++  java
  • 第八天springboot整合redis

    1.编程思路:

      1.启动虚拟机,并加载redis

            (1)VMware Workstation Pro:

      

       (2)xshell加载redis

       完成虚拟机的redis启动

      2.springboot加载依赖,配置配置文件

      redis配置文件

        

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>

           application.yml 加载配置

        

    #Redis
      redis:
        host: 192.168.181.10
        port: 6379

      3.进行测试

    package com.xhn;
    
    import com.xhn.pojo.Muser;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.data.redis.core.RedisTemplate;
    import org.springframework.test.context.junit4.SpringRunner;
    
    
    @RunWith(SpringRunner.class)
    //加载主启动类
    @SpringBootTest(classes = 自己的主启动类.class)
    public class AppTest {
    
        //依赖注入
    
        @Autowired
        private RedisTemplate redisTemplate;
    
        @Test
        public void testRedis(){
            //redis存入数据
            redisTemplate.opsForValue().set("来了来了他来了","来了老弟");
            //redis去除数据
          String str=(String) redisTemplate.opsForValue().get("来了来了他来了");
            System.out.println(str);
            Muser muser=new Muser(1,"asan","123","印度三哥");
            redisTemplate.opsForValue().set("user",muser);
    
            Muser user =(Muser) redisTemplate.opsForValue().get("user");
            System.out.println(user);
        }
    }

      4.查看运行结果

     完成测试

  • 相关阅读:
    使用国内镜像安装pyqt5
    python线程池 ThreadPoolExecutor 的用法及实战
    进程和线程、协程的区别
    python线程池实现
    python 多进程使用总结
    参与开源项目
    脑图——前端技术
    HTML中DTD使用小结
    浅谈面向对象——追溯法
    Dva.js 里面的几个概念
  • 原文地址:https://www.cnblogs.com/xinghaonan/p/11804053.html
Copyright © 2011-2022 走看看