• 第八天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.查看运行结果

     完成测试

  • 相关阅读:
    CF163E e-Government
    P2336 [SCOI2012]喵星球上的点名
    数据结构
    数字逻辑
    建筑制图与识图
    建筑施工
    电力系统分析
    现代物流基础
    电子商务网站设计与管理
    数字电子技术基础
  • 原文地址:https://www.cnblogs.com/xinghaonan/p/11804053.html
Copyright © 2020-2023  润新知