File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
springboot-webflux-6-redis/src/main/java/org/spring/springboot/webflux/controller Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .spring .springboot .webflux .controller ;
2
+
3
+ import org .spring .springboot .domain .City ;
4
+ import org .springframework .beans .factory .annotation .Autowired ;
5
+ import org .springframework .data .redis .core .ReactiveRedisTemplate ;
6
+ import org .springframework .data .redis .core .ReactiveValueOperations ;
7
+ import org .springframework .web .bind .annotation .*;
8
+ import reactor .core .publisher .Mono ;
9
+
10
+ @ RestController
11
+ @ RequestMapping (value = "/city2" )
12
+ public class CityWebFluxReactiveController {
13
+
14
+ @ Autowired
15
+ private ReactiveRedisTemplate reactiveRedisTemplate ;
16
+
17
+ @ GetMapping (value = "/{id}" )
18
+ public Mono <City > findCityById (@ PathVariable ("id" ) Long id ) {
19
+ String key = "city_" + id ;
20
+ ReactiveValueOperations <String , City > operations = reactiveRedisTemplate .opsForValue ();
21
+ Mono <City > city = operations .get (key );
22
+ return city ;
23
+ }
24
+
25
+ @ PostMapping
26
+ public Mono <City > saveCity (@ RequestBody City city ) {
27
+ String key = "city_" + city .getId ();
28
+ ReactiveValueOperations <String , City > operations = reactiveRedisTemplate .opsForValue ();
29
+ return operations .getAndSet (key , city );
30
+ }
31
+
32
+ @ DeleteMapping (value = "/{id}" )
33
+ public Mono <Long > deleteCity (@ PathVariable ("id" ) Long id ) {
34
+ String key = "city_" + id ;
35
+ return reactiveRedisTemplate .delete (key );
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments