#SpringBoot# SpringBoot2.x整合Redis

分佈式緩存Redis

爲什麼要用緩存和介紹什麼是Redis,新手練習工具 ​

1、redis官網 https://redis.io/download

2、新手入門redis在線測試工具:http://try.redis.io/

源碼編譯安裝Redis4.x

使用源碼安裝Redis4.x和配置外網訪問

1、快速安裝  https://redis.io/download#installation
		wget http://download.redis.io/releases/redis-4.0.9.tar.gz
		tar xzf redis-4.0.9.tar.gz
		cd redis-4.0.9
		make

		啓動服務端:src/redis-server
		啓動客戶端:src/redis-cli

2、默認是本地訪問的,需要開放外網訪問
	1)打開redis.conf文件在NETWORK部分修改
	   註釋掉bind 127.0.0.1可以使所有的ip訪問redis
	   修改 protected-mode,值改爲no

SpringBoot2.x整合redis實戰

簡介:使用springboot-starter整合reids實戰

	1、官網:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-redis
		集羣文檔:https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#cluster

	2、springboot整合redis相關依賴引入
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
    
 	3、相關配置文件配置
		#=========redis基礎配置=========
		spring.redis.database=0
		spring.redis.host=127.0.0.1
		spring.redis.port=6390
		# 連接超時時間 單位 ms(毫秒)
		spring.redis.timeout=3000

		#=========redis線程池設置=========
		# 連接池中的最大空閒連接,默認值也是8。
		spring.redis.pool.max-idle=200

		#連接池中的最小空閒連接,默認值也是0。
		spring.redis.pool.min-idle=200
		
		# 如果賦值爲-1,則表示不限制;pool已經分配了maxActive個jedis實例,則此時pool的狀態爲exhausted(耗盡)。
		spring.redis.pool.max-active=2000

		# 等待可用連接的最大時間,單位毫秒,默認值爲-1,表示永不超時
		spring.redis.pool.max-wait=1000
    
   4、常見redistemplate種類講解和緩存實操(使用自動注入)

		1、注入模板
		@Autowired
		private StirngRedisTemplate strTplRedis

		2、類型String,List,Hash,Set,ZSet
		對應的方法分別是opsForValue()、opsForList()、opsForHash()、opsForSet()、opsForZSet()

Redis工具

1、常用客戶端 https://redisdesktop.com/download ​	

在這裏插入圖片描述
公衆號: 自學it的攻城獅(id:study458)

發佈了59 篇原創文章 · 獲贊 4 · 訪問量 5123
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章