redistemplate使用的是jdkserializationredisserializer
stringredistemplate使用的是stringredisserializer
redistemplate使用的序列類在在運算元據的時候,比如說存入資料會將資料先序列化成位元組陣列
然後在存入redis資料庫,這個時候開啟redis檢視的時候,你會看到你的資料不是以可讀的形式
展現的,而是以位元組陣列顯示,類似下面
如果你的資料是複雜的物件型別,而取出的時候又不想做任何的資料轉換,直接從redis裡面取出乙個物件,那麼使用redistemplate是更好的選擇。
當你的redis資料庫裡面本來存的是字串資料或者你要訪問的資料就是字串型別資料的時候,那麼你就使用stringredistemplate即可。
@test
public void test()
stringredistemplate.opsforvalue().set("test", "100",60*10,timeunit.seconds);//向redis裡存入資料和設定快取時間
stringredistemplate.boundvalueops("test").increment(-1);//val做-1操作
stringredistemplate.opsforvalue().get("test")//根據key獲取快取中的val
stringredistemplate.boundvalueops("test").increment(1);//val +1
stringredistemplate.getexpire("test")//根據key獲取過期時間
stringredistemplate.getexpire("test",timeunit.seconds)//根據key獲取過期時間並換算成指定單位
stringredistemplate.delete("test");//根據key刪除快取
stringredistemplate.haskey("546545");//檢查key是否存在,返回boolean值
stringredistemplate.opsforset().add("red_123", "1","2","3");//向指定key中存放set集合
stringredistemplate.expire("red_123",1000 , timeunit.milliseconds);//設定過期時間
stringredistemplate.opsforset().ismember("red_123", "1")//根據key檢視集合中是否存在指定資料
stringredistemplate.opsforset().members("red_123");//根據key獲取set集合
springboot 中Redis快取應用
第一在主啟動類中 加入 enablecaching enablecaching 開啟註解 public static void main string args 注意面向前端的vo 需要例項化 實現 serializable介面 要不然會報錯 1.在我們處理的類中加上快取註解 怎麼理解呢?其實我們這...
Redis快取應用場景
記錄一下自己的聽課筆記,看的網課。參考資料 快取一些常用的 經常訪問的 不經常變化的資料,也就是相對穩定即時性低的,比如說 選單 許可權 類別 資料字典。這樣的資料放快取是因為文章的閱讀量和點讚量變化太快了,如果頻繁的更新資料庫,資料庫壓力太大了,頂不住的。如果放到redis中快取起來,讀寫更快。加...
快取 redis 快取穿透
哪一些因素 考慮使用redis,畢竟 redis 也要增加成本 1 熱點資料 2 讀的成本非常大 3 讀多寫少 4 對資料一致性要求 沒有那麼嚴格 可以出現資料與資料庫不一致 1 秒殺場景 3 物流查詢軌跡 熱點資料 啟用的資料是被快取到redis 當中 快取key 乙個時間點過期的時候,如果快取資...