spring boot webflux必會必知系列教程第07課中redis實現(xiàn)緩存_第1頁
spring boot webflux必會必知系列教程第07課中redis實現(xiàn)緩存_第2頁
spring boot webflux必會必知系列教程第07課中redis實現(xiàn)緩存_第3頁
spring boot webflux必會必知系列教程第07課中redis實現(xiàn)緩存_第4頁
spring boot webflux必會必知系列教程第07課中redis實現(xiàn)緩存_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、07WebFlux Redis RedisTemplate Redis Reactive Reactive ReactiveRedisTemplateReactiveRedisTemplate CityWebFluxReactiveController /city2 Re s t Con t r o ll e rRe qu e s tMa p( v a l u e = / c it y2 )pub li c c l a ss C it yWe bF l uxReac ti v eCon t r o ll e rAu t owi r e dp r i v a t e Reac ti v eRe

2、d i s Temp l a t er eac ti v eRe d i s Temp l a t e ;Ge tMa( v a l u e = / i d )pub li c Mono f i ndC it yBy I d (P a t hVa r i a b l e ( i d ) Long S t r i ng k e y = c it y_ + i d ;Reac ti v eVa l u eOp e r a ti on s op e r a ti on s = p s Fo rVa l u e () ;Mono c it y = op e r a ti on s . g e t (

3、k e y ) ; r e t u r n c it y ;i d )r eac ti v eRe d i s Temp l a t e . otMapub li c Mono s a v eC it y (Re qu e s t Body C it y c it y ) S t r i ng k e y = c it y_ + c it y . g e t I d () ;Reac ti v eVa l u eOp e r a ti on s op e r a ti on s = p s Fo rVa l u e () ;r e t u r n op e r a ti on s . g e

4、t AndSe t ( k e y ,c it y ) ;r eac ti v eRe d i s Temp l a t e . oDe l e t eMa( v a l u e = / i d )pub li c Mono d e l e t eC it y (P a t hVa r i a b l e ( i d ) Longi d ) S t r i ng k e y = c it y_ + i d ;r e t u r n r eac ti v eRe d i s Temp l a t e . d e l e t e ( k e y ) ;Autowired ReactiveRedis

5、Template ReactiveValueOperations String value ReactiveHashOperations ReactiveListOperationsReactiveSetOperations ReactiveZSetOperations set City get Mono Flux Redis pom.xml maven perties mongodb handler controller CityWebFluxControllerRe s t Con t r o ll e rRe qu e s tMa p( v a l u e

6、= / c it y )pub li c c l a ss C it yWe bF l uxCon t r o ll e rAu t owi r e dp r i v a t e C it yHa nd l e rc it yHa nd l e r ;Ge tMa( v a l u e = / i d )pub li c Mono f i ndC it yBy I d (P a t hVa r i a b l e ( i d ) r e t u r n c it yHa nd l e r . f i ndC it yBy I d ( i d ) ;Longi d )Ge tMa() pub l

7、i c F l ux f i ndAll C it y ()r e t u r n c it yHa nd l e r . f i ndAll C it y () ;tMa() pub li c Mono s a v eC it y (Re qu e s t Body C it y c it y ) r e t u r n c it yHa nd l e r . s a v e ( c it y ) ;Pu tMa() pub li c Mono mod i f yC it y (Re qu e s t Body C it y c it y ) r e t u r n c it yHa nd

8、l e r .mod i f yC it y ( c it y ) ;De l e t eMa( v a l u e = / i d )pub li c Mono d e l e t eC it y (P a t hVa r i a b l e ( i d ) Longi d ) r e t u r n c it yHa nd l e r . d e l e t eC it y ( i d ) ;CityHandler Cacheable Mono / Flux Serializable Redis Cache asideRead throughWrite throughWritebehind

9、 caching Cache Aside Cache Cache Compon e n tpub li c c l a ss C it yHa nd l e r p r i v a t ei c f i n a l Logg e r LOGGER = Logg e r Fac t o r y . g e t Logg e r( C it yHa nd l e r . c l a ss ) ;Au t owi r e dp r i v a t e Re d i s Temp l a t e r e d i s Temp l a t e ;p r i v a t e f i n a l C it

10、yRit o r y c it yRit o r y ;Au t owi r e dpub li c C it yHa nd l e r( C it yReit o r y c it yReit o r y ) t h i s . c it yit o r y = c it yit o r y ;pub li c Monor e t u r n c it ys a v e ( C it y c it y ) it o r y . s a v e ( c it y ) ;pub li c Monof i ndC it yBy I d ( Long i d ) / S t r i ng k e y

11、 = c it y_ + i d ;Va l u eOp e r a ti on s op e r a ti on s = r e d i s Temp l a t e . op s Fo rVa l u e () ;/ h a sKe y = r e d i s Temp l a t e . h a sKe y ( k e y ) ; ( h a sKe y ) C it y c it y = op e r a ti on s . g e t ( k e y ) ;i fLOGGER . i n f o ( C it yHa nd l e r . f i ndC it yBy I d ()

12、: + c it y .t oS t r i ng () ;r e t u r n Mono . c r ea t e ( c it yMonoS i nk - c it yMonoS i nk .s ( c it y ) ;/ MongoDB Mono c it yMono = c it yit o r y . f i ndBy I d ( i d ) ;i f ( c it yMono = nu ll )r e t u r n c it yMono ;/ c it yMono . s ub s c r i b e ( c it yOb j- op e r a ti on s . s e t

13、 ( k e y ,c it yOb j ) ;LOGGER . i n f o ( C it yHa nd l e r . f i ndC it yBy I d () : +c it yOb j . t oS t r i ng () ; ) ;r e t u r n c it yMono ;pub li c F l uxr e t u r n c it yf i ndAll C it y ()it o r y . f i ndAll () . cac h e () ;pub li c Monomod i f yC it y ( C it y c it y )Mono c it yMono =

14、 c it yit o r y . s a v e ( c it y ) ;/ S t r i ng k e y = c it y_ + c it y . g e t I d () ;h a sKe y = r e d i s Temp l a t e . h a sKe y ( k e y ) ; i f( h a sKe y )r e d i s Temp l a t e . d e l e t e ( k e y ) ;LOGGER . i n f o ( C it yHa nd l e r .mod i f yC it y (): ID + c it e t I d () ;r e t

15、 u r n c it yMono ;pub li c Mono d e l e t eC it y ( Longi d )c it yit o r y . d e l e t eBy I d ( i d ) ;/ S t r i ng k e y = c it y_ + i d ;h a sKe y = r e d i s Temp l a t e . h a sKe y ( k e y ) ; i f( h a sKe y )r e d i s Temp l a t e . d e l e t e ( k e y ) ;LOGGER . i n f o ( C it yHa nd l e

16、r . d e l e t eC it y (): ID + i d )r e t u r n Mono . c r ea t e ( c it yMonoS i nk - c it yMonoS i nk . s us ( i d ) ; RedisTemplate Spring JdbcTemplate RedisTemplate RedisConnection Redis String StringRedisTemplatea. ndCityById DB b. deleteCity / modifyCity Redis IDEA Maven Project Tab Maven inst

17、all Maven c d s p r i ngboo t -we b f l ux - 7 -r e d i s - cac h emvn c l ea ni n s t a ll .INFOINFOINFOINFOINFOINFOINFO- BUI LD SUCS- To t a ltime :01 : 30 mi nF i n i s h e d a t:2018 - 10 - 15T10 : 00 : 54+08 : 00F i n a l Memo r y :31M/ 174M- IDEA Application Debug .2018 - 04 - 10 08 : 43 : 39

18、. 932INFO 2052 - c t o r- h tt p - n i o - 1 r . i p c . n e tt y . t c p . B l o c k i ngNon/ 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 : 8080e tt yCon t e x t: S t a r t e d Htt pSe r v e r2018 - 04 - 10 08 : 43 : 39 . 935INFO 2052 - ma i n o . s . b . we b . emb e dd e d . n e tt yNe tt yWe bSe r v e r: Ne tt ys t a r t e d on po r t ( s ) :INFO 2052 -80802018 - 04 - 10 08 : 43 : 39 . 960ma

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論