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字符串

  • 相关阅读:
    JavaScript语言基础
    IP地址分类及CIDR划分方法
    Python静态方法实现单实例模式
    【转载】http和socket之长连接和短连接
    DDoS攻击
    Vue自定义过滤器
    解决跨域问题
    微信菜单创建
    canvas标签(1)--线条、矩形、圆形、文本、阴影、抛小球
    Bootstrap CSS概览代码文字标注篇
  • 原文地址:https://www.cnblogs.com/tiancai/p/9019438.html
Copyright © 2011-2022 走看看