日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java redis快速入门_SpringDataRedis快速入门

發(fā)布時間:2024/9/19 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java redis快速入门_SpringDataRedis快速入门 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.pom引入依賴

redis.clients

jedis

2.9.0

org.springframework.data

spring-data-redis

2.0.5.RELEASE

2.新增配置文件 redis-config.properties

redis.host=127.0.0.1

redis.port=6379

redis.pass=

redis.database=0

redis.maxIdle=300

redis.maxWait=3000

maxWait:連接池中連接用完時,新的請求等待時間,毫秒

maxIdle: 最大閑置個數

3.新增spring配置文件applicationContext-redis.xml

xmlns:cache="http://www.springframework.org/schema/cache"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/beans/spring-cache.xsd">

p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/>

4.創(chuàng)建枚舉用于存放

package com.qingcheng.utlis;

public enum CacheKey {

AD,//廣告

SKU_PRICE,//價格

CATEGORY_TREE;//商品分類導航樹

}

5.注入redisTemplate使用,此處使用的存入枚舉,當然也可以用其他的

redisTemplate.boundValueOps(CacheKey.CATEGORY_TREE).set(categoryTree);

6.啟動項目初始化的類調用,當項目啟動會自動執(zhí)行這個方法

@Component

public class Init implements InitializingBean {

@Autowired

private AdService adService;

public void afterPropertiesSet() throws Exception {

System.out.println("緩存預熱");

adService.positions();

}

}

總結

以上是生活随笔為你收集整理的java redis快速入门_SpringDataRedis快速入门的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。