package com.dzq.demo.sys.auth.rest; import com.dzq.demo.common.webcomponent.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @RestController @RequestMapping("redis-test") public class RedisTest { @Autowired private RedisTemplate<String, String> redisTemplate; @Autowired private StringRedisTemplate stringRedisTemplate; @RequestMapping(method = RequestMethod.GET) public Response test(HttpServletRequest request) { //設置指定鍵的值 、 獲取指定鍵的值 redisTemplate.opsForValue().set("key", "value"); redisTemplate.opsForValue().get("key"); /** * 其餘類型的操做方法 redisTemplate.opsForHash() redisTemplate.opsForList() redisTemplate.opsForSet() redisTemplate.opsForZSet() */ //設置指定鍵的值 、 獲取指定鍵的值 redisTemplate.boundValueOps("key").set("value"); redisTemplate.boundValueOps("key").get(); /** *其餘類型的操做方法 redisTemplate.boundHashOps("key") redisTemplate.boundListOps("key") redisTemplate.boundSetOps("key") redisTemplate.boundZSetOps("key") */ return Response.success(); } }