zoukankan      html  css  js  c++  java
  • SpringBoot整合Redis

    1.所需包

    <!-- springboot整合redis -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>


    2.配置
    #redis  
    spring.redis.hostName=127.0.0.1
    spring.redis.port=6379
    spring.redis.pool.maxActive=8
    spring.redis.pool.maxWait=-1
    spring.redis.pool.maxIdle=8
    spring.redis.pool.minIdle=0
    spring.redis.timeout=0

    3.demo
    package com.example.demo;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.redis.core.RedisTemplate;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    
    
    @RestController
    public class HiController {
        
        @Autowired
        private RedisTemplate redisTemplate;
    
    
        @RequestMapping(value = "/redis",method = RequestMethod.GET)
        public Set<String> redis(){
            Set<String> list=new HashSet<>();
     redisTemplate.opsForSet().add("kk","k1","k2");
            redisTemplate.opsForSet().add("kk","k3","k4");
    
            return  redisTemplate.opsForSet().members("kk");
        }
    }
    

     4.结果

    访问 http://localhost:8765/redis, 即可看到返回的json字符串

  • 相关阅读:
    html5shiv.js-让IE浏览器支持HTML5标准
    CSS2系列:外边距合并问题(margincollapse)
    HTML5:离线存储(缓存机制)-IndexDB
    CSS3系列:流式(弹性)布局(flex布局)
    Sublime Text 3 常用插件以及安装方法(转)
    后台配置参数写在文件上
    20160414
    2016413
    20160412
    网页设计素材网站
  • 原文地址:https://www.cnblogs.com/tiancai/p/9019438.html
Copyright © 2011-2022 走看看