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

  • 相关阅读:
    GDB编辑、搜索源码以及在线帮助
    GDB查看栈信息
    GDB信号处理
    GDB反向调试
    GDB调试多进程程序
    GDB后台调试命令
    GDB non-stop模式
    GDB调试多线程程序
    GDB禁用删除断点
    解决Mac OS下Eclipse、IntelliJ IDEA打开其他窗口默认全屏
  • 原文地址:https://www.cnblogs.com/tiancai/p/9019438.html
Copyright © 2011-2022 走看看