From 27dea59f56c5930067fd8c152368a7e6a24fc769 Mon Sep 17 00:00:00 2001 From: liqiangqiang Date: Wed, 2 May 2018 19:06:57 +0800 Subject: [PATCH] =?UTF-8?q?WebFlux=20=E4=BD=BF=E7=94=A8=20ReactiveRedisTem?= =?UTF-8?q?plate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CityWebFluxReactiveController.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 springboot-webflux-6-redis/src/main/java/org/spring/springboot/webflux/controller/CityWebFluxReactiveController.java diff --git a/springboot-webflux-6-redis/src/main/java/org/spring/springboot/webflux/controller/CityWebFluxReactiveController.java b/springboot-webflux-6-redis/src/main/java/org/spring/springboot/webflux/controller/CityWebFluxReactiveController.java new file mode 100644 index 00000000..69677073 --- /dev/null +++ b/springboot-webflux-6-redis/src/main/java/org/spring/springboot/webflux/controller/CityWebFluxReactiveController.java @@ -0,0 +1,37 @@ +package org.spring.springboot.webflux.controller; + +import org.spring.springboot.domain.City; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.ReactiveRedisTemplate; +import org.springframework.data.redis.core.ReactiveValueOperations; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +@RestController +@RequestMapping(value = "/city2") +public class CityWebFluxReactiveController { + + @Autowired + private ReactiveRedisTemplate reactiveRedisTemplate; + + @GetMapping(value = "/{id}") + public Mono findCityById(@PathVariable("id") Long id) { + String key = "city_" + id; + ReactiveValueOperations operations = reactiveRedisTemplate.opsForValue(); + Mono city = operations.get(key); + return city; + } + + @PostMapping + public Mono saveCity(@RequestBody City city) { + String key = "city_" + city.getId(); + ReactiveValueOperations operations = reactiveRedisTemplate.opsForValue(); + return operations.getAndSet(key, city); + } + + @DeleteMapping(value = "/{id}") + public Mono deleteCity(@PathVariable("id") Long id) { + String key = "city_" + id; + return reactiveRedisTemplate.delete(key); + } +}