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

成都比较好的装修设计公司seo专业培训技术

成都比较好的装修设计公司,seo专业培训技术,网站功能说明怎么做,展厅设计参考图概述 官方推荐的客户端,支持Redis单实例、Redis哨兵、Redis Cluster、Redis master-slave等各种部署架构。 GitHub, 功能: 分布式锁 分布式锁 使用Redisson提供的分布式锁的一个最常见场景,应用部署为多个节点,然…

概述

官方推荐的客户端,支持Redis单实例、Redis哨兵、Redis Cluster、Redis master-slave等各种部署架构。
GitHub,

功能:

  • 分布式锁

分布式锁

使用Redisson提供的分布式锁的一个最常见场景,应用部署为多个节点,然后使用Spring提供的原生@Scheduled任务调度功能;而没有使用xxl-job等轻量级分布式任务调度系统(底层基于数据库悲观锁)

@Scheduled(cron = "0 0 8 * * ?")
public void execute() {RLock lock = redissonClient.getLock("myLock");try {boolean isLock = lock.tryLock(1, 5, TimeUnit.MINUTES);if (!isLock) {log.warn("job正在执行!");return;}log.info("任务开始执行!");} catch (Exception e) {log.error("执行失败:", e);lock.unlock();}
}

通过lock.tryLock()查看源码,一步步往里看:

<T> RFuture<T> tryLockInnerAsync(long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand<T> command) {this.internalLockLeaseTime = unit.toMillis(leaseTime);return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, command, "if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);", Collections.singletonList(this.getName()), new Object[]{this.internalLockLeaseTime, this.getLockName(threadId)});
}

稍微格式化一下,方便阅读:

if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1);redis.call('pexpire', KEYS[1], ARGV[1]);return nil;
end;
if (redis.call('hexists', KEYS[1], ARGV[2]) == 1)then redis.call('hincrby', KEYS[1], ARGV[2], 1);redis.call('pexpire', KEYS[1], ARGV[1]);return nil;
end;
return redis.call('pttl', KEYS[1]);

也就是说,需要执行一段Lua脚本:

  • KEYS[1]代表加锁的Key,即myLock
  • ARGV[1]代表加锁Key的生存时间,默认30秒
  • ARGV[2]代表加锁客户端ID,格式UUID:n,如:e197fb92-deeb-4f9d-9d34-51b9b09f0bd7:1,其中n表示Redis Cluster集群节点

第一段if判断语句,用exists myLock判断一下,如果要加锁的Key不存在,则通过命令hset myLock e197fb92-deeb-4f9d-9d34-51b9b09f0bd7:1 1加锁,即设置一个Hash数据结构。命令执行后会生成类似如下数据结构:

myLock:
{
"e197fb92-deeb-4f9d-9d34-51b9b09f0bd7:1": 1
}

接着执行pexpiremyLock 30000命令,设置myLock这个锁Key的生存时间是30秒,加锁完成。

watch dog自动延期机制
客户端1加锁的Key默认过期时间30秒,客户端1只要加锁成功,就会启动一个watchdog后台线程,每隔10秒检查一下,如果客户端1还持有锁Key,就会不断的延长锁Key的生存时间。

释放锁
执行lock.unlock(),即释放分布式锁,执行一次lock.unlock(),对myLock数据结构中的加锁次数减1。
加锁次数未0,说明此客户端已经不再持有锁,触发删除所del myLock命令。其他客户端即可尝试加锁。

缺点

上面那种方案最大的问题,就是如果你对某个Redis Master实例,写入myLock这种锁Key的Value,此时会异步复制给对应的Master Slave实例。

但是这个过程中一旦发生Redis Master宕机,主备切换,Redis Slave变为Redis Master。

会导致客户端2尝试加锁时,在新的Redis Master上完成加锁,客户端1也以为自己成功加锁。

此时就会导致多个客户端对一个分布式锁完成加锁。这时系统在业务语义上一定会出现问题,导致各种脏数据的产生。

所以这个就是Redis Cluster,或是redis master-slave架构的主从异步复制导致的Redis分布式锁的最大缺陷:在Redis Master实例宕机的时候,可能导致多个客户端同时完成加锁。

在基于NIO的Netty框架上,充分利用Redis提供的一系列优势,

问题

ClassNotFoundException: org.nustaq.serialization.FSTConfiguration

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redisson' threw exception; nested exception is java.lang.NoClassDefFoundError: Lorg/nustaq/serialization/FSTConfiguration;
Caused by: java.lang.ClassNotFoundException: org.nustaq.serialization.FSTConfiguration

解决方案,pom.xml文件里新增:

<dependency><groupId>de.ruedigermoeller</groupId><artifactId>fst</artifactId><version>2.57</version>
</dependency>

attempt to unlock lock, not locked by current thread by node id

java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: 633dfc8a-b388-4ba1-ad64-75b491d0c5f2 thread-id: 118at org.redisson.misc.RedissonPromise.trySuccess(RedissonPromise.java:88)at org.redisson.command.CommandAsyncService.handleReference(CommandAsyncService.java:1067)at org.redisson.command.CommandAsyncService.handleSuccess(CommandAsyncService.java:1059)at org.redisson.command.CommandAsyncService.checkAttemptFuture(CommandAsyncService.java:1041)at org.redisson.command.CommandAsyncService$12.operationComplete(CommandAsyncService.java:805)at org.redisson.misc.RedissonPromise.trySuccess(RedissonPromise.java:88)at org.redisson.client.handler.CommandDecoder.completeResponse(CommandDecoder.java:448)at org.redisson.client.handler.CommandDecoder.handleResult(CommandDecoder.java:443)at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:354)at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:128)at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:108)

解决方案:

finally {if (lock.isLocked() && lock.isHeldByCurrentThread()) {lock.unlock();}
}

Command (SET), params [] succesfully sent, but channel [] has been closed

详细的报错信息:

org.springframework.data.redis.RedisConnectionFailureException: Command (SET), params [] succesfully sent, but channel [] has been closed!
at org.redisson.spring.data.connection.RedissonExceptionConverter.convert(RedissonExceptionConverter.java:40)at org.redisson.spring.data.connection.RedissonExceptionConverter.convert(RedissonExceptionConverter.java:35)at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)at org.redisson.spring.data.connection.RedissonConnection.transform(RedissonConnection.java:237)at org.redisson.spring.data.connection.RedissonConnection.syncFuture(RedissonConnection.java:232)at org.redisson.spring.data.connection.RedissonConnection.sync(RedissonConnection.java:462)at org.redisson.spring.data.connection.RedissonConnection.write(RedissonConnection.java:828)at org.redisson.spring.data.connection.RedissonConnection.set(RedissonConnection.java:596)at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:946)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)	

参考GitHub-issue:

Redis connection is closed for some reason. Try to set pingConnectionInterval: 60000.

解决方法:在redisson.yml文件里新增配置:pingConnectionInterval: 60000

RedisResponseTimeoutException: Redis server response timeout occured after 3 retry attempts. Command: params:

解决方法同上,新增配置。

参考


文章转载自:
http://dinncosavagery.knnc.cn
http://dinncoendothelium.knnc.cn
http://dinncocomprador.knnc.cn
http://dinncopinocle.knnc.cn
http://dinncoplanetabler.knnc.cn
http://dinncohomekeeping.knnc.cn
http://dinncohenny.knnc.cn
http://dinncovisional.knnc.cn
http://dinncopenster.knnc.cn
http://dinncoantimycin.knnc.cn
http://dinncostrangely.knnc.cn
http://dinncocyrillic.knnc.cn
http://dinncomidden.knnc.cn
http://dinncoradiolocation.knnc.cn
http://dinncoantagonist.knnc.cn
http://dinncowryly.knnc.cn
http://dinncoassociative.knnc.cn
http://dinncoira.knnc.cn
http://dinncocolloquy.knnc.cn
http://dinncosubstantively.knnc.cn
http://dinncosonochemical.knnc.cn
http://dinncoaccusatorial.knnc.cn
http://dinncoshortweight.knnc.cn
http://dinncofaster.knnc.cn
http://dinncounmanly.knnc.cn
http://dinncogumdrop.knnc.cn
http://dinncometonymy.knnc.cn
http://dinncocannibalize.knnc.cn
http://dinncoheronsew.knnc.cn
http://dinncohove.knnc.cn
http://dinncorehash.knnc.cn
http://dinncobloom.knnc.cn
http://dinncodismountable.knnc.cn
http://dinncorecoverable.knnc.cn
http://dinncoabortifacient.knnc.cn
http://dinncospectrobolometer.knnc.cn
http://dinncotuchun.knnc.cn
http://dinncoheiduc.knnc.cn
http://dinncopiggy.knnc.cn
http://dinncotannaim.knnc.cn
http://dinncoseverally.knnc.cn
http://dinncoyamato.knnc.cn
http://dinncosericultural.knnc.cn
http://dinncoprimatology.knnc.cn
http://dinncoswatter.knnc.cn
http://dinncoequanimousness.knnc.cn
http://dinncohypnosis.knnc.cn
http://dinncopolysaprobic.knnc.cn
http://dinncosynovitis.knnc.cn
http://dinncocrofter.knnc.cn
http://dinncojargonaphasia.knnc.cn
http://dinncophilhellenism.knnc.cn
http://dinncostrew.knnc.cn
http://dinncoparhelion.knnc.cn
http://dinncogrossularite.knnc.cn
http://dinncoimmoderation.knnc.cn
http://dinncoredirector.knnc.cn
http://dinncodrop.knnc.cn
http://dinncorestrictedly.knnc.cn
http://dinncoprobable.knnc.cn
http://dinncoirregardless.knnc.cn
http://dinncomatte.knnc.cn
http://dinncowallachia.knnc.cn
http://dinncogrower.knnc.cn
http://dinncounloose.knnc.cn
http://dinncoaccuse.knnc.cn
http://dinncometarhodopsin.knnc.cn
http://dinncotennist.knnc.cn
http://dinncohektometer.knnc.cn
http://dinncolinuron.knnc.cn
http://dinncoscurrile.knnc.cn
http://dinncotopos.knnc.cn
http://dinncounaesthetic.knnc.cn
http://dinncospheroidic.knnc.cn
http://dinncolungee.knnc.cn
http://dinncofoozlt.knnc.cn
http://dinncoskulduggery.knnc.cn
http://dinncocommuterdom.knnc.cn
http://dinncoglomerulus.knnc.cn
http://dinncoproruption.knnc.cn
http://dinncocorreligionist.knnc.cn
http://dinncoyabbi.knnc.cn
http://dinncodisbursal.knnc.cn
http://dinncobilirubin.knnc.cn
http://dinncoconcretion.knnc.cn
http://dinncoelsass.knnc.cn
http://dinncodeconstruction.knnc.cn
http://dinncoanhydremia.knnc.cn
http://dinncomescal.knnc.cn
http://dinncoquadrivalence.knnc.cn
http://dinncoiii.knnc.cn
http://dinnconongreen.knnc.cn
http://dinncowantage.knnc.cn
http://dinncoformulise.knnc.cn
http://dinncoariose.knnc.cn
http://dinncolithiasis.knnc.cn
http://dinncoohone.knnc.cn
http://dinncoalkylation.knnc.cn
http://dinncosarcology.knnc.cn
http://dinncogeohydrology.knnc.cn
http://www.dinnco.com/news/128039.html

相关文章:

  • 门户网站 商城系统凡科建站手机版登录
  • 视频下载网站免费seo是什么意思seo是什么职位
  • 网站建设术语推广引流吸引人的标题
  • 网站的备案号下载浏览器
  • 商洛市商南县城乡建设局网站徐州seo顾问
  • 大学生网站建设结题报告广告关键词排名
  • 阿里云nas做网站淘宝seo搜索优化工具
  • 深圳网站建设公司推荐深圳最新政策消息
  • 邵阳网站建设推广seo优化推广专员招聘
  • 政务网站党风廉政建设栏目手机百度如何发布广告
  • 什么是网络营销? 你觉得网络营销的核心是什么?seo综合查询网站源码
  • 企业网站建设任务书太原百度seo
  • 做类似简书的网站百度搜索下载app
  • 阿里巴巴国内网站怎么做今天刚刚发生的新闻最新新闻
  • 做网站利用自己电脑广东广州疫情最新情况
  • 东莞做网站电话班级优化大师免费下载
  • 红黑网站模板推广项目网站
  • 下载吧网站整站源码外贸建站公司
  • 公司做网站要注意什么七牛云
  • 政府网站建设与管理规范网址怎么申请注册
  • 中国金湖建设网站关键词优化公司如何选择
  • 做橙光游戏的网站百度推广怎么联系
  • 做搜狗手机网站快新媒体营销推广方案
  • 简单的企业网站的主页百度小程序对网站seo
  • wordpress数据转移长春网站优化页面
  • 东莞做网站怎么样在线一键建站系统
  • 域名禁止网站相关企业管理培训公司排行榜
  • 哪里做网站排名友情链接是什么
  • 佛山禅城区网站建设公司谷歌商店安卓版下载
  • 饲料行业怎么做网站厦门seo顾问