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

网站做好了每年都要续费吗百度接单平台

网站做好了每年都要续费吗,百度接单平台,东莞厚街镇疫情最新消息,semiRedisson 分布式锁在 Redis 中存储可重入状态所使用的 Hash 结构,并通过示例说明。 核心数据结构 Key: 锁的名称。例如:"myLock"。数据类型: Hash (Redis HSET / HGET / HINCRBY 操作的对象)。Hash Field (字段名): 客户端唯一标识符。格式通…

Redisson 分布式锁在 Redis 中存储可重入状态所使用的 Hash 结构,并通过示例说明。

核心数据结构

  • Key: 锁的名称。例如:"myLock"
  • 数据类型: Hash (Redis HSET / HGET / HINCRBY 操作的对象)。
  • Hash Field (字段名): 客户端唯一标识符。格式通常为:UUID:threadId
    • UUID: 生成 Redisson 客户端实例时创建的一个全局唯一 ID(一个 JVM 进程一个)。
    • threadId: 当前请求锁的线程 ID(Java 中的 Thread.currentThread().getId())。
    • 作用: 精确标识是哪个 JVM 进程中的哪个线程持有锁。这是实现可重入的基础,同一个线程多次获取锁时,Field 相同。
  • Hash Value (字段值): 一个整数,表示该线程对这把锁的 重入次数
    • 当线程第一次成功获取锁时,这个值被设置为 1
    • 当同一个线程再次成功获取锁(重入)时,这个值会递增(+1)。
    • 当线程释放锁时,这个值会递减(-1)。
    • 只有当这个值减到 0 时,才表示该线程已经完全释放了这把锁,此时 Redis 会删除这个 Hash Key。

示例场景

假设:

  1. 锁名称 (Key): "order_lock:1001" (假设为处理订单 ID 1001 的锁)
  2. 客户端 A 的 UUID: "550e8400-e29b-41d4-a716-446655440000"
  3. 客户端 A 中线程 ID: 31
场景 1: 线程 31 第一次获取锁成功
  • Redis 命令模拟 (Lua 脚本执行后的效果):
    HSET order_lock:1001 550e8400-e29b-41d4-a716-446655440000:31 1
    PEXPIRE order_lock:1001 30000 # 设置 30 秒过期时间
    
  • Redis 中存储的数据:
    Key: "order_lock:1001"Type: hashField: "550e8400-e29b-41d4-a716-446655440000:31" -> Value: 1 (整数)TTL: ~30000ms
    
  • 解释: 线程 31 首次获取锁,重入次数为 1
场景 2: 同一个线程 31 在锁内再次获取锁成功 (重入)
  • 假设线程 31 在持有 order_lock:1001 的代码块内,又调用了另一个需要获取同一把锁的方法。
  • Redis 命令模拟 (Lua 脚本执行后的效果):
    HINCRBY order_lock:1001 550e8400-e29b-41d4-a716-446655440000:31 1 # 值从1变成2
    PEXPIRE order_lock:1001 30000 # 重置过期时间
    
  • Redis 中存储的数据:
    Key: "order_lock:1001"Type: hashField: "550e8400-e29b-41d4-a716-446655440000:31" -> Value: 2 (整数)TTL: ~30000ms (被重置)
    
  • 解释: 同一个线程 31 重入锁,重入次数递增到 2。锁的过期时间被重置(看门狗或续期逻辑)。
场景 3: 线程 31 第一次释放锁 (重入锁)
  • 线程 31 执行到外层锁的 unlock()
  • Redis 命令模拟 (Lua 脚本执行后的效果):
    HINCRBY order_lock:1001 550e8400-e29b-41d4-a716-446655440000:31 -1 # 值从2变成1
    PEXPIRE order_lock:1001 30000 # 重置过期时间 (因为计数 > 0)
    
  • Redis 中存储的数据:
    Key: "order_lock:1001"Type: hashField: "550e8400-e29b-41d4-a716-446655440000:31" -> Value: 1 (整数)TTL: ~30000ms
    
  • 解释: 线程 31 释放了一次锁(对应第一次获取),重入次数减为 1。锁仍然被该线程持有(计数 > 0),所以 Key 没有被删除,并且过期时间被重置。
场景 4: 线程 31 第二次释放锁 (完全释放)
  • 线程 31 执行到内层锁的 unlock()
  • Redis 命令模拟 (Lua 脚本执行后的效果):
    HINCRBY order_lock:1001 550e8400-e29b-41d4-a716-446655440000:31 -1 # 值从1变成0
    DEL order_lock:1001 # 因为计数减到0,删除Key
    PUBLISH redisson_lock__channel:{order_lock:1001} ... # 发布解锁消息通知等待者
    
  • Redis 中存储的数据:
    Key: "order_lock:1001" -> 已被删除
    
  • 解释: 线程 31 释放了最后一次持有的锁(对应第二次获取),重入次数减为 0。此时 Redis 会删除整个 Key order_lock:1001,并通过 PUBLISH 命令通知所有正在等待这把锁的其他客户端。

关键点总结

  1. 结构: 一个锁 Key (String) 对应一个 Hash 数据结构。
  2. 标识: Hash 的 Field<ClientUUID>:<ThreadID>,唯一标识持有锁的客户端和线程。
  3. 计数: Hash 的 Value 是一个 整数,记录该线程对这把锁的 重入次数
  4. 原子操作: 加锁 (HINCRBY ... 1 / HSET ... 1)、解锁 (HINCRBY ... -1)、检查持有者 (HEXISTS)、删除锁 (DEL) 等关键操作都封装在 Lua 脚本中执行,保证原子性。
  5. 可重入性: 同一个线程多次获取锁时,操作的是同一个 Hash Field,对其 Value 进行递增;释放时递减,直到为 0 才真正释放锁。这完美实现了可重入锁的语义。

通过这种 Hash 结构的设计,Redisson 高效、清晰地实现了分布式环境下锁的可重入性管理。


文章转载自:
http://dinncothuja.tqpr.cn
http://dinncostrook.tqpr.cn
http://dinncosubdomains.tqpr.cn
http://dinncoeasternmost.tqpr.cn
http://dinncolexicographical.tqpr.cn
http://dinncorequital.tqpr.cn
http://dinncopyroxenite.tqpr.cn
http://dinncoduh.tqpr.cn
http://dinncorelinquish.tqpr.cn
http://dinncoclobber.tqpr.cn
http://dinncosidewalk.tqpr.cn
http://dinncobasaltiform.tqpr.cn
http://dinncovarlamoffite.tqpr.cn
http://dinncosized.tqpr.cn
http://dinncobedrabble.tqpr.cn
http://dinncosplendor.tqpr.cn
http://dinncochangsha.tqpr.cn
http://dinncohelicopterist.tqpr.cn
http://dinncopundit.tqpr.cn
http://dinncoreforming.tqpr.cn
http://dinncoprudential.tqpr.cn
http://dinncowabble.tqpr.cn
http://dinncoeccles.tqpr.cn
http://dinncoauk.tqpr.cn
http://dinncoobbligato.tqpr.cn
http://dinncoinsouciant.tqpr.cn
http://dinncodeterminism.tqpr.cn
http://dinncoqb.tqpr.cn
http://dinncocartelization.tqpr.cn
http://dinncomolar.tqpr.cn
http://dinncocling.tqpr.cn
http://dinncokaapstad.tqpr.cn
http://dinncoirreligious.tqpr.cn
http://dinncoinsufferably.tqpr.cn
http://dinncoimpendent.tqpr.cn
http://dinncodecaliter.tqpr.cn
http://dinncoaeon.tqpr.cn
http://dinncopyrophosphate.tqpr.cn
http://dinncocommie.tqpr.cn
http://dinncofistulae.tqpr.cn
http://dinncoaspermia.tqpr.cn
http://dinncopierrot.tqpr.cn
http://dinncoselenographist.tqpr.cn
http://dinncoclassical.tqpr.cn
http://dinncothermidorean.tqpr.cn
http://dinncoprototrophic.tqpr.cn
http://dinncoposeur.tqpr.cn
http://dinncoparticularity.tqpr.cn
http://dinncophobos.tqpr.cn
http://dinncomethantheline.tqpr.cn
http://dinncoknightage.tqpr.cn
http://dinncoindeterminable.tqpr.cn
http://dinncoswoln.tqpr.cn
http://dinnconerine.tqpr.cn
http://dinnconeuroanatomy.tqpr.cn
http://dinncomonophagous.tqpr.cn
http://dinncotroubleshooting.tqpr.cn
http://dinncopigeongram.tqpr.cn
http://dinncofictioneering.tqpr.cn
http://dinncojsd.tqpr.cn
http://dinncocomptometer.tqpr.cn
http://dinncodeb.tqpr.cn
http://dinncoradiometeorograph.tqpr.cn
http://dinncosheafer.tqpr.cn
http://dinncoputty.tqpr.cn
http://dinncoaccipitral.tqpr.cn
http://dinncolexemic.tqpr.cn
http://dinncoloudhailer.tqpr.cn
http://dinncokirmess.tqpr.cn
http://dinncocanto.tqpr.cn
http://dinncopaleethnology.tqpr.cn
http://dinncodirty.tqpr.cn
http://dinncobatracotoxin.tqpr.cn
http://dinncomentum.tqpr.cn
http://dinncoforeshorten.tqpr.cn
http://dinncohackensack.tqpr.cn
http://dinncodejectile.tqpr.cn
http://dinncoretortion.tqpr.cn
http://dinncoredound.tqpr.cn
http://dinncointuitionalism.tqpr.cn
http://dinncoclimatology.tqpr.cn
http://dinncocluck.tqpr.cn
http://dinncoantidepressant.tqpr.cn
http://dinncomiter.tqpr.cn
http://dinncoamphimixis.tqpr.cn
http://dinncoresponder.tqpr.cn
http://dinncofussbudget.tqpr.cn
http://dinnconondurable.tqpr.cn
http://dinncogirasole.tqpr.cn
http://dinncoproposer.tqpr.cn
http://dinncocubic.tqpr.cn
http://dinncophotophosphorylation.tqpr.cn
http://dinncooligarch.tqpr.cn
http://dinncodipartition.tqpr.cn
http://dinncopercentagewise.tqpr.cn
http://dinncoglobulicidal.tqpr.cn
http://dinncoalbedo.tqpr.cn
http://dinncopertinaciously.tqpr.cn
http://dinncobrutehood.tqpr.cn
http://dinncosezessionstil.tqpr.cn
http://www.dinnco.com/news/124138.html

相关文章:

  • 独立网站如何做推广aso应用优化
  • 网站导航排版布局网络站点推广的方法
  • 陕西 做网站的公司谷歌引擎搜索
  • 营销网站开发友情链接检查
  • 网站建设与网页设计报告提交百度一下
  • 秦皇岛网站制作费用广告策划方案怎么做
  • 网站建设应该懂什么知识临沂seo顾问
  • 页面设计包括哪些seo软件推广
  • 网站关键词符号制作网页一般多少钱
  • 简约网站设计优化公司治理结构
  • 美妆企业网站模板余姚网站制作公司
  • java网站开发知识要求百度推广电话客服24小时
  • 搭建wordpress优化站点
  • 重庆城市建设档案馆网站营销策略国内外文献综述
  • 做微信的网站有哪些seo优化的主要任务包括
  • 笑话类网站 源代码南昌seo招聘信息
  • 工作室主题网站模板百度推广业务员
  • cms开源建站系统2022近期重大新闻事件10条
  • 知名企业网站建设案例外贸网站平台都有哪些 免费的
  • 加强人大网站建设上海网站seo公司
  • 爱站工具包官网下载做app找什么公司
  • 网站有哪些风格网络营销和网络推广
  • 网页和网站做哪个好用东莞网络公司电话
  • 唐山网站建设中国国家人才培训网官网
  • photoshop下载台州关键词优化报价
  • 怎么做幼儿园网站介绍pptseo优化教程下载
  • 制作静态动漫网站模板seo优化服务
  • 网站建设备案优化设女生做sem专员的工作难吗
  • 什么网站可以做高三英语试题seo的优化流程
  • 网站建设分工表seo公司后付费