springboot2 x基礎 整合redis

2021-10-01 13:12:25 字數 1566 閱讀 2070

在springboot中一般使用redistemplate提供的方法來操作redis。那麼使用springboot整合redis

需要那些步驟呢。

環境安裝(任選)

centos7 搭建redis-5單機服務

centos7 搭建 redis-5 cluster 集群服務

在專案中新增 spring-boot-starter-data-redis 依賴

org.springframework.boot

spring-boot-starter-data-redis

@configuration

public class redisconfig

}

redis:

# redis資料庫索引(預設為0)

database: 0

# redis伺服器位址

host: 127.0.0.1

# redis伺服器連線埠

port: 6379

# redis伺服器連線密碼(預設為空)

password:

# 連線池最大連線數(使用負值表示沒有限制)

pool:

max-active: 8

# 連線池最大阻塞等待時間(使用負值表示沒有限制)

max-wait: -1

# 連線池中的最大空閒連線

max-idle: 8

# 連線池中的最小空閒連線

min-idle: 0

# 連線超時時間(毫秒) 不能設為0 不然啟動連線報超時異常

timeout: 500

//一定要掃瞄 不然直接使用工具類報空指標異常

@compent

public class cacheutils

/*** 儲存到hash集合中

** @param hname 集合名

* @param key

* @param value

*/public static void hashset(string hname, string key, string value)

/*** 從hash集合裡取得

** @param hname

* @param key

* @return

*/public static object hashget(string hname, string key)

/**省略 n 多方法

。。。。。。*/}

@runwith(springrunner.class)

@test

public void test() throws exception

}

**我已放到 碼雲,匯入 springboot-examples 專案

基於SpringBoot 2 X整合Druid

說明 本文旨在整理springboot 2.x整合druid基礎功能,如有問題請指出 參考資料 基於springboot 2.x版本,這裡是引入druid spring boot2 starter的方式來配置,所以不需要不需要configbean來配置druid,如果引入的是druid,則需要con...

SpringBoot2 x 整合Druid詳細步驟

druid spring boot starter模式 這種方式比較簡單,不需要自己寫配置類。在匯入依賴以及配置好配置檔案yml即可。pom.xml com.alibaba druid spring boot starter 1.1.10 spring datasource url jdbc mys...

spring boot2 x訪問靜態資源

此處對比兩個spring boot版本訪問靜態資源的區別 jdk分別為1.7與1.8 1.5.9.release 2.1.6.release 資源未被攔截 可以訪問 可以訪問 資源被攔截 可以訪問 不可以訪問 由此可見,如果spring boot版本為2.x,那存在配置了靜態資源後不能被訪問的情況。...