package com.fzy.javastudy.java.day_0905;
import com.fzy.javastudy.spring.apimodel.Api;
import com.fzy.javastudy.spring.apimodel.ApiResponse;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
@RestController
@RequestMapping("/day_0905")
public class RedisTestController {
@Resource
private RedisTemplate<String, Integer> redisTemplate;
@Resource
private RedisTemplate<String, String> stringRedisTemplate;
@GetMapping("test1")
public ApiResponse test1() {
redisTemplate.opsForValue().set("test1_key1", 12);
int value = redisTemplate.opsForValue().get("test1_key1");
System.out.println(value);
return Api.ok(value);
}
@GetMapping("test2")
public ApiResponse test2() {
stringRedisTemplate.opsForValue().set("test2_key2", "hello", 10, TimeUnit.SECONDS);
String value = stringRedisTemplate.opsForValue().get("test2_key2");
System.out.println(value);
return Api.ok(value);
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。