中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

網(wǎng)站如何快速被baud百度一下

網(wǎng)站如何快速被,baud百度一下,主題網(wǎng)站設(shè)計(jì)與制作,nas可以做網(wǎng)站服務(wù)器文章目錄 前言Redission詳細(xì)配置步驟pom依賴application.yaml配置類CacheConfigEnvironmentContext RedissionController單測 前言 本篇博客是SpringBoot整合Redission,若文章中出現(xiàn)相關(guān)問題,請(qǐng)指出! 所有博客文件目錄索引:博客…

文章目錄

  • 前言
  • Redission詳細(xì)配置步驟
    • pom依賴
    • application.yaml
    • 配置類
      • CacheConfig
      • EnvironmentContext
    • RedissionController
    • 單測

最新消息資訊熱點(diǎn)圍觀公眾號(hào)首圖

前言

本篇博客是SpringBoot整合Redission,若文章中出現(xiàn)相關(guān)問題,請(qǐng)指出!

所有博客文件目錄索引:博客目錄索引(持續(xù)更新)

Redission集成到springboot是有兩種場景的,第一個(gè)場景是針對(duì)單臺(tái)節(jié)點(diǎn),第二個(gè)場景是針對(duì)多臺(tái)節(jié)點(diǎn)。

當(dāng)前配置是單臺(tái)節(jié)點(diǎn)

配套源碼地址:

  • gitee:https://gitee.com/changluJava/demo-exer/tree/master/SpringBoot/springboot-redission
  • github:https://github.com/changluya/Java-Demos/tree/master/SpringBoot/springboot-redission

Redission詳細(xì)配置步驟

image-20241218170628525。

pom依賴

    <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.redisson</groupId><artifactId>redisson-spring-boot-starter</artifactId><version>3.17.7</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency></dependencies>

application.yaml

server:port: 8055
spring:redis:host: 127.0.0.1port: 6379database: 1password: 123456
# 直接配置參數(shù)
#redisson:
#  codec: org.redisson.codec.JsonJacksonCodec
#  threads: 4
#  netty:
#    threads: 4
#  single-server-config:
#    address: "redis://localhost:6379"
#    password: 123456
#    database: 0

配置類

CacheConfig

package com.changlu.redission.config;import io.micrometer.core.instrument.util.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class CacheConfig {@Autowiredprivate EnvironmentContext environmentContext;@Beanpublic RedissonClient redissonClient(){Config config = new Config();config.setTransportMode(TransportMode.NIO);String redisPassword = getRedisPassword();int redisDB = environmentContext.getRedisDB();// 單節(jié)點(diǎn)服務(wù)器SingleServerConfig singleServerConfig = config.useSingleServer();singleServerConfig.setAddress(getRedissonAddress());singleServerConfig.setDatabase(redisDB);if (StringUtils.isNotBlank(redisPassword)) {singleServerConfig.setPassword(redisPassword);}return Redisson.create(config);}private String getRedissonAddress() {return "redis://" + environmentContext.getRedisUrl() + ":" + environmentContext.getRedisPort();}public String getRedisPassword() {String redisPassword;try {redisPassword = environmentContext.getRedisPassword();} catch (Exception e) {redisPassword = environmentContext.getRedisPassword();}return redisPassword;}}

EnvironmentContext

package com.changlu.redission.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;@Component
public class EnvironmentContext {@Autowiredprivate Environment environment;public String getRedisSentinel() {return environment.getProperty("spring.redis.sentinel.nodes", "");}public int getRedisDB() {return Integer.parseInt(environment.getProperty("spring.redis.database", "1"));}public String getRedisUrl() {return environment.getProperty("spring.redis.host", "127.0.0.1");}public String getRedisPassword() {return environment.getProperty("spring.redis.password");}public int getRedisPort() {return Integer.parseInt(environment.getProperty("spring.redis.port", "6379"));}
}

RedissionController

package com.changlu.redission.controller;import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;@RestController
@RequestMapping("/redission")
public class RedissionController {@Autowiredprivate RedissonClient redissonClient;@GetMapping("/key/{key}")public Map<String, String> redission(@PathVariable("key")String key) {RLock rLock = redissonClient.getLock(key);try {boolean lock = rLock.tryLock(10, 20, TimeUnit.SECONDS);System.out.println("lock: " + lock);if (lock) {//業(yè)務(wù)Thread.sleep(1000 * 10);}} catch (Throwable e) {e.printStackTrace();} finally {if (rLock.isLocked() && rLock.isHeldByCurrentThread()) {rLock.unlock();}System.out.println("解鎖");}return new HashMap<>();}}

單測

@SpringBootTest(classes = SpringbootRedissionApplication.class)
@RunWith(SpringRunner.class)
public class TestApplication {@AutowiredApplicationContext context;// redisson客戶端@AutowiredRedissonClient redissonClient;// 測試分布式鎖@Testpublic void terst1() throws InterruptedException {RLock lock = redissonClient.getLock("anyLock");new Thread(() -> {lock.lock();try {System.out.println(Thread.currentThread().getName() + ":\t 獲得鎖");Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();} finally {System.out.println(Thread.currentThread().getName() + ":\t 釋放鎖");lock.unlock();}}).start();new Thread(() -> {lock.lock();try {System.out.println(Thread.currentThread().getName() + ":\t 獲得鎖");Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();} finally {System.out.println(Thread.currentThread().getName() + ":\t 釋放鎖");lock.unlock();}}).start();Thread.sleep(100000);}
}
http://www.risenshineclean.com/news/51978.html

相關(guān)文章:

  • 網(wǎng)站如何做點(diǎn)擊鏈接地址網(wǎng)絡(luò)推廣是以企業(yè)產(chǎn)品或服務(wù)
  • 彩妝網(wǎng)站模板手機(jī)cpu性能增強(qiáng)軟件
  • 北京專業(yè)建設(shè)網(wǎng)站公司哪家好seo推廣官網(wǎng)
  • 小型電子商務(wù)網(wǎng)站規(guī)劃廊坊關(guān)鍵詞優(yōu)化報(bào)價(jià)
  • 四川長昕建設(shè)工程有限公司網(wǎng)站友情鏈接怎么連
  • 51ape是誰做的網(wǎng)站推廣app最快的方法
  • 長春市長春網(wǎng)站建設(shè)網(wǎng)百度免費(fèi)安裝
  • 網(wǎng)站建設(shè)的目標(biāo)是什么 提供了哪些欄目seo崗位是什么意思
  • 互聯(lián)網(wǎng)網(wǎng)站建設(shè)制作中國最好的網(wǎng)絡(luò)營銷公司
  • 客服在線為您服務(wù)廣州網(wǎng)站運(yùn)營專業(yè)樂云seo
  • 做網(wǎng)站哪家公司最好文案代寫收費(fèi)標(biāo)準(zhǔn)
  • 技術(shù)先進(jìn)的網(wǎng)站設(shè)計(jì)制作來賓seo
  • 門戶網(wǎng)站建設(shè)審批程序網(wǎng)絡(luò)營銷的方法包括哪些
  • 有哪些線上做酒店的網(wǎng)站aso優(yōu)化師
  • 如何自己創(chuàng)造網(wǎng)站網(wǎng)站seo需要用到哪些工具
  • 網(wǎng)站怎樣做百度推廣網(wǎng)站建設(shè)是什么工作
  • 成都網(wǎng)站設(shè)計(jì)開發(fā)做得好怎樣做網(wǎng)絡(luò)推廣營銷
  • 溫州首頁網(wǎng)絡(luò)科技有限公司什么建站程序最利于seo
  • 網(wǎng)站怎么做定時(shí)任務(wù)免費(fèi)創(chuàng)建網(wǎng)站的平臺(tái)
  • 網(wǎng)站關(guān)鍵詞的優(yōu)化在哪做比較開放的瀏覽器
  • 中國建設(shè)行業(yè)網(wǎng)杭州百度人工優(yōu)化
  • 做網(wǎng)站客戶怎么找常用的網(wǎng)絡(luò)推廣手段有哪些
  • 做網(wǎng)站需要域名 域名是啥seo外包網(wǎng)站
  • 汽車門戶網(wǎng)站源碼網(wǎng)頁開發(fā)公司
  • 東莞seo網(wǎng)站優(yōu)化產(chǎn)品宣傳方式有哪些
  • 網(wǎng)站做淘寶推廣收入優(yōu)化營商環(huán)境條例心得體會(huì)
  • 網(wǎng)站建設(shè)問題運(yùn)營推廣計(jì)劃
  • 大航母網(wǎng)站建設(shè)與服務(wù)山西seo排名廠家
  • 微信做網(wǎng)站的弊端百度一下百度搜索
  • 網(wǎng)站優(yōu)化檢測百度網(wǎng)頁推廣怎么做