Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liqiangqiang
committed
May 2, 2018
1 parent
f2c7644
commit 27dea59
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...src/main/java/org/spring/springboot/webflux/controller/CityWebFluxReactiveController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<City> findCityById(@PathVariable("id") Long id) { | ||
String key = "city_" + id; | ||
ReactiveValueOperations<String, City> operations = reactiveRedisTemplate.opsForValue(); | ||
Mono<City> city = operations.get(key); | ||
return city; | ||
} | ||
|
||
@PostMapping | ||
public Mono<City> saveCity(@RequestBody City city) { | ||
String key = "city_" + city.getId(); | ||
ReactiveValueOperations<String, City> operations = reactiveRedisTemplate.opsForValue(); | ||
return operations.getAndSet(key, city); | ||
} | ||
|
||
@DeleteMapping(value = "/{id}") | ||
public Mono<Long> deleteCity(@PathVariable("id") Long id) { | ||
String key = "city_" + id; | ||
return reactiveRedisTemplate.delete(key); | ||
} | ||
} |