天天看點

SpringBoot2.x整合redis

        1.springboot整合redis相關依賴引入

            <dependency>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-starter-data-redis</artifactId>

            </dependency>

        2、相關配置檔案配置

            #=========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()

繼續閱讀