内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

springboot整合redis實(shí)例分析

這篇文章主要介紹了springboot整合redis實(shí)例分析的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇springboot整合redis實(shí)例分析文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。

成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、嘉蔭網(wǎng)絡(luò)推廣、小程序開發(fā)、嘉蔭網(wǎng)絡(luò)營(yíng)銷、嘉蔭企業(yè)策劃、嘉蔭品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供嘉蔭建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.rwnh.cn

導(dǎo)入redis pom文件

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-	redis</artifactId>
        </dependency>

編寫redis配置

spring:
  redis:
    password:
    port: 6379
    host: localhost
    database: 0
    jedis:
      pool:
        ## 連接池最大連接數(shù)(使用負(fù)值表示沒(méi)有限制)
        #spring.redis.pool.max-active=8
        max-active: 8
        ## 連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒(méi)有限制)
        #spring.redis.pool.max-wait=-1
        max-wait: -1
        ## 連接池中的最大空閑連接
        #spring.redis.pool.max-idle=8
        max-idle: 8
        ## 連接池中的最小空閑連接
        #spring.redis.pool.min-idle=0
        min-idle: 0
      ## 連接超時(shí)時(shí)間(毫秒)
    lettuce:
      shutdown-timeout: 0

編寫springConfig文件

由于存儲(chǔ)需要序列化,所以我們要配置redis的序列化方式,如果不配置的話key和value默認(rèn)使用的都是StringRedisSerializer,只能用來(lái)存儲(chǔ)String類型的數(shù)據(jù),因此需要配置我們常用的類型。同時(shí)我們的Java實(shí)體類也要一定要繼承Serializable接口

@Configuration
public class RedisConfig {

    @Bean
    public RedisTemplate<String , Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(factory);

        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        ObjectMapper om = new ObjectMapper();
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//        om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        jackson2JsonRedisSerializer.setObjectMapper(om);

        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        // key采用String的序列化方式
        template.setKeySerializer(stringRedisSerializer);
        // hash的key也采用String的序列化方式
        template.setHashKeySerializer(stringRedisSerializer);
        // value序列化方式采用jackson
        template.setValueSerializer(jackson2JsonRedisSerializer);
        // hash的value序列化方式采用jackson
        template.setHashValueSerializer(jackson2JsonRedisSerializer);
        template.afterPropertiesSet();
        return template;
    }

}

測(cè)試redis

在這一步前,我們要確定所連接的redis服務(wù)已經(jīng)開啟

@Autowired
    private RedisTemplate<String , Object> redisTemplate;
@Test
    public void testSelect() throws SQLException {
        redisTemplate.opsForValue().set("qqq",userMapper.findByUname("zengkaitian"));
        System.out.println("redis中獲取的:"+redisTemplate.opsForValue().get("qqq"));
    }

測(cè)試結(jié)果
springboot整合redis實(shí)例分析

關(guān)于“springboot整合redis實(shí)例分析”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“springboot整合redis實(shí)例分析”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前名稱:springboot整合redis實(shí)例分析
本文地址:http://www.rwnh.cn/article12/ipcigc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄響應(yīng)式網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)網(wǎng)站改版、網(wǎng)站導(dǎo)航、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
钟祥市| 白山市| 通辽市| 新兴县| 楚雄市| 望奎县| 武定县| 海原县| 滨州市| 陈巴尔虎旗| 虎林市| 合作市| 德格县| 宜丰县| 措勤县| 通榆县| 夏津县| 昌平区| 电白县| 上栗县| 涞源县| 望谟县| 额敏县| 荥阳市| 府谷县| 万全县| 桑植县| 太仆寺旗| 寻乌县| 云南省| 望江县| 资兴市| 太和县| 精河县| 张北县| 恩平市| 永德县| 东乌| 磐石市| 美姑县| 河曲县|