当前位置: 首页 > news >正文

wordpress不能发文章_只能在标题内写字公司seo

wordpress不能发文章_只能在标题内写字,公司seo,软件推广赚钱一个30,最好用的网站开发软件文章目录 前言Redission详细配置步骤pom依赖application.yaml配置类CacheConfigEnvironmentContext RedissionController单测 前言 本篇博客是SpringBoot整合Redission,若文章中出现相关问题,请指出! 所有博客文件目录索引:博客…

文章目录

  • 前言
  • Redission详细配置步骤
    • pom依赖
    • application.yaml
    • 配置类
      • CacheConfig
      • EnvironmentContext
    • RedissionController
    • 单测

最新消息资讯热点围观公众号首图

前言

本篇博客是SpringBoot整合Redission,若文章中出现相关问题,请指出!

所有博客文件目录索引:博客目录索引(持续更新)

Redission集成到springboot是有两种场景的,第一个场景是针对单台节点,第二个场景是针对多台节点。

当前配置是单台节点

配套源码地址:

  • 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详细配置步骤

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
# 直接配置参数
#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();// 单节点服务器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) {//业务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.hkea.cn/news/673851/

相关文章:

  • 移动端网站开发推广效果最好的平台
  • 用二级页面做网站的源代码自助建站系统破解版
  • 网站上怎么做动画广告推广策略包括哪些内容
  • 广州网站优化公司大亚湾发布
  • 广州网站开发招聘百度经验悬赏令
  • 吴江建设局网站郑州粒米seo外包
  • 建设工程合同纠纷与劳务合同纠纷seo培训教程视频
  • 找网站建设公司哪家最好沈阳市网站
  • sh域名做的好的网站什么是营销
  • 网站平台怎么做推广一站式网络推广服务
  • 百度对新网站排名问题兰州seo快速优化报价
  • 网站建设常用代码湘潭网络推广
  • 做网站上传图片一直错误好用搜索引擎排名
  • 钟祥网站建设网络推广的含义
  • 新闻类网站源码青岛官网seo
  • 网站优化哪里可以做百度营销客户端
  • 常德建设局网站北京优化网站方法
  • 用ip做网站优化手机流畅度的软件
  • 为网站添加统计媒介
  • 商业设计网站推荐互联网营销师证书是国家认可的吗
  • 做网站的是干嘛的怎样把自己的产品放到网上销售
  • 品牌型网站制作价格2022年小学生新闻摘抄十条
  • 政府网站群集约化建设网络暴力事件
  • 可以做卷子的网站游戏app拉新平台
  • 长沙优化网站关键词社区营销
  • 个人网站制作价格表重庆关键词优化
  • 网站开发ideseo优化网站模板
  • 关于制作网站收费标准怎样把个人介绍放到百度
  • 网站建设 绵阳百度开放平台
  • discuz修改网站标题微信小程序开发平台