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

  • 相关阅读:
    POJ 3253 Fence Repair
    POJ 2431 Expedition
    NYOJ 269 VF
    NYOJ 456 邮票分你一半
    划分数问题 DP
    HDU 1253 胜利大逃亡
    NYOJ 294 Bot Trust
    NYOJ 36 最长公共子序列
    HDU 1555 How many days?
    01背包 (大数据)
  • 原文地址:https://www.cnblogs.com/tiancai/p/9019438.html
Copyright © 2011-2022 走看看