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.查看运行结果

     完成测试

  • 相关阅读:
    在win2003中发布部署vs2010b2写的mvc2网站
    安装blender2.5Alpha0
    Win7下虚拟机个人使用小结:Virtual PC,VMware和VirtualBox
    ASP.NET AJAX Control Toolkit Beta 0911 发布[再增两控件]
    Camtasia 6录屏时鼠标闪烁问题解决
    为XNA制做安装程序(四)WIX Toolset 3.0 for Visual Studio 2008
    Oracle EM 12c
    无题
    从徐汇到虹口
    近况
  • 原文地址:https://www.cnblogs.com/xinghaonan/p/11804053.html
Copyright © 2011-2022 走看看