Redis在SpringBoot的常用操作

2021-09-28 19:26:34 字數 1365 閱讀 1933

我們一般情況下,使用redis或許更多還是去存session,但是redis還是有很多更廣遠的操作,這裡先列舉幾個比較簡單的和springboot的相結合的比較簡單的操作。

redistemplate.

opsforvalue()

.set

("test"

,"100",60

*10,timeunit.seconds)

;//向redis裡存入資料和設定快取時間

redistemplate.

opsforvalue()

.get

("test");

//根據key獲取快取中的val

redistemplate.

boundvalueops

("test").

increment(-

1);//val做-1操作

redistemplate.

boundvalueops

("test").

increment(1

);//val +1

redistemplate.

getexpire

("test");

//根據key獲取過期時間

redistemplate.

getexpire

("test"

,timeunit.seconds)

;//根據key獲取過期時間並換算成指定單位

redistemplate.

delete

("test");

//根據key刪除快取

redistemplate.

haskey

("546545");

//檢查key是否存在,返回boolean值

redistemplate.

expire

("red_123"

,1000

, timeunit.milliseconds)

;//設定過期時間

redistemplate.

opsforset()

.add

("red_123"

,"1"

,"2"

,"3");

//向指定key中存放set集合

redistemplate.

opsforset()

.ismember

("red_123"

,"1");

//根據key檢視集合中是否存在指定資料

redistemplate.

opsforset()

.members

("red_123");

//根據key獲取set集合

使用Systemd包裝SpringBoot應用

為應用建立乙個service檔案 unit description springboot rest service service user ubuntu 要執行程式的路徑 呼叫jar檔案的shell執行檔案 succes itstatus 143 timeoutstopsec 10 restart...

logback日誌整合springboot設定

1.logback spring.xml 1.0 encoding utf 8 此xml在spring boot 1.5.3.release.jar裡 org springframework boot logging logback defaults.xml 開啟後可以通過jmx動態控制日誌級別 s...

使用idea建立第乙個springboot專案

前言 如今springboot越來越火,越來越多的公司選擇使用springboot作為專案的開發框架,其設計目的就是用來簡化spring專案的搭建和開發過程,省略了傳統spring springmvc專案繁瑣的配置,可以讓開發人員快速上手。下面詳細說明下如何使用idea建立我們的第乙個springb...