1. 程式人生 > >springboot+redis(史上最簡單)

springboot+redis(史上最簡單)

1, pom.xml

        <dependency>
            <groupId>org.springframework.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>1.5.3.RELEASE</version>
        </dependency>

2, application.properties

spring:
   redis:
      host: 0.0.0.0(you redis server ip)
      port: 6379(you redis server port)
      password: 123456(you redis server password)
      database: 0(you redis server database)
      jedis:
        pool:
          min-idle: 0
          max-active: 8
          max-idle: 8
          max-wait: -1ms

3, 盡請使用

package com.equaker.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.support.json.JSONWriter;
import com.equaker.mapper.cluster.UserMapper;
import com.equaker.mapper.master.EQMapper;
import com.equaker.model.EQ;
import com.equaker.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("demo")
public class DemoController {

    private static Logger log = LoggerFactory.getLogger(DemoController.class);

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @RequestMapping("/save")
    @ResponseBody
    public EQ save(){
        redisTemplate.opsForValue().set("name","equaker");
        log.info(redisTemplate.opsForValue().get("name"));
        return eq;
    }

  

}

4, 更多用法請參考

http://www.cnblogs.com/spihz/p/8548800.html