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

地方门户网站发展趋势怎么在百度做免费推广

地方门户网站发展趋势,怎么在百度做免费推广,wordpress 调试模式,食品类网站设计为了生成一个符合要求的分布式全局ID,我们可以使用 StringRedisTemplate 来实现。这个ID由三部分组成: 符号位(1 bit):始终为0,表示正数。时间戳(31 bit):表示从某个起始…

为了生成一个符合要求的分布式全局ID,我们可以使用 StringRedisTemplate 来实现。这个ID由三部分组成:

  1. 符号位(1 bit):始终为0,表示正数。
  2. 时间戳(31 bit):表示从某个起始时间点(例如2023-01-01 00:00:00)到现在的秒数。
  3. 序列号(32 bit):用于在同一秒内生成不同的ID。

实现步骤

  1. 计算时间戳:从某个起始时间点到现在的秒数。
  2. 生成序列号:使用Redis的原子递增操作来生成序列号。
  3. 组合ID:将时间戳和序列号组合成一个64位的长整型数字。

代码实现

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.TimeUnit;@Service
public class DistributedIdGenerator {@Autowiredprivate StringRedisTemplate stringRedisTemplate;// 起始时间点,例如2023-01-01 00:00:00private static final long EPOCH = ZonedDateTime.of(2023, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000;// 序列号的Redis键前缀private static final String SEQUENCE_KEY_PREFIX = "sequence:";/*** 生成分布式全局ID** @return 分布式全局ID*/public long generateId() {// 获取当前时间戳(从起始时间点到现在的秒数)long currentTimeSec = Instant.now().getEpochSecond() - EPOCH;// 生成序列号String sequenceKey = SEQUENCE_KEY_PREFIX + currentTimeSec;long sequence = stringRedisTemplate.opsForValue().increment(sequenceKey, 1);if (sequence >= (1L << 32)) { // 序列号溢出,重置为0stringRedisTemplate.expire(sequenceKey, 1, TimeUnit.SECONDS); // 设置1秒后过期sequence = 0;}// 组合IDlong id = (currentTimeSec << 32) | sequence;return id;}
}

代码解释

  1. EPOCH:起始时间点,例如2023-01-01 00:00:00,转换为秒数。
  2. SEQUENCE_KEY_PREFIX:Redis中存储序列号的键前缀。
  3. generateId 方法
    • currentTimeSec:从起始时间点到现在的秒数。
    • sequenceKey:根据当前时间戳生成的Redis键。
    • sequence:使用 opsForValue().increment 方法生成序列号,确保在同一秒内生成不同的ID。
    • 序列号溢出处理:如果序列号达到最大值(2^32 - 1),则重置为0,并设置键在1秒后过期。
    • 组合ID:将时间戳左移32位,然后与序列号进行按位或操作,生成最终的64位ID。

测试代码

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class IdController {@Autowiredprivate DistributedIdGenerator idGenerator;@GetMapping("/generate-id")public long generateId() {return idGenerator.generateId();}
}


文章转载自:
http://dinncononcontrastive.tqpr.cn
http://dinncoallantoic.tqpr.cn
http://dinncokersey.tqpr.cn
http://dinncocriticality.tqpr.cn
http://dinncothivel.tqpr.cn
http://dinncotachygrapher.tqpr.cn
http://dinncopersuasion.tqpr.cn
http://dinncoropework.tqpr.cn
http://dinncoringdove.tqpr.cn
http://dinncodaraf.tqpr.cn
http://dinncosympathetectomy.tqpr.cn
http://dinncosynchromesh.tqpr.cn
http://dinncotbs.tqpr.cn
http://dinncoella.tqpr.cn
http://dinncosoarable.tqpr.cn
http://dinncoscleroblast.tqpr.cn
http://dinncomainsheet.tqpr.cn
http://dinncolightheartedness.tqpr.cn
http://dinncosweetsop.tqpr.cn
http://dinncodefamatory.tqpr.cn
http://dinncotellurize.tqpr.cn
http://dinncoembourgeoisification.tqpr.cn
http://dinncocoulometer.tqpr.cn
http://dinncotrisomy.tqpr.cn
http://dinncocsce.tqpr.cn
http://dinncosorbonne.tqpr.cn
http://dinncoinvoluntarily.tqpr.cn
http://dinncoseparately.tqpr.cn
http://dinncogolfer.tqpr.cn
http://dinncogel.tqpr.cn
http://dinncocalfhood.tqpr.cn
http://dinncolampoonery.tqpr.cn
http://dinncoingratiating.tqpr.cn
http://dinncopomona.tqpr.cn
http://dinncorufus.tqpr.cn
http://dinncoask.tqpr.cn
http://dinncosolmization.tqpr.cn
http://dinncounseal.tqpr.cn
http://dinncostethoscopy.tqpr.cn
http://dinncooverclothes.tqpr.cn
http://dinncorankly.tqpr.cn
http://dinncoubiquitously.tqpr.cn
http://dinncoinnavigable.tqpr.cn
http://dinncofort.tqpr.cn
http://dinncooptics.tqpr.cn
http://dinncointercept.tqpr.cn
http://dinncoexsert.tqpr.cn
http://dinncoabd.tqpr.cn
http://dinncoeatage.tqpr.cn
http://dinncosvd.tqpr.cn
http://dinncobitterbrush.tqpr.cn
http://dinncobilge.tqpr.cn
http://dinncowoorali.tqpr.cn
http://dinncononreader.tqpr.cn
http://dinncounderappreciated.tqpr.cn
http://dinncoowelty.tqpr.cn
http://dinncomonsveneris.tqpr.cn
http://dinncobursarial.tqpr.cn
http://dinncocheek.tqpr.cn
http://dinncocircumstanced.tqpr.cn
http://dinncoradiumize.tqpr.cn
http://dinncoorthodontics.tqpr.cn
http://dinncojournalist.tqpr.cn
http://dinncosanguine.tqpr.cn
http://dinncobewilderment.tqpr.cn
http://dinncosoubrette.tqpr.cn
http://dinncopraisable.tqpr.cn
http://dinncozinnia.tqpr.cn
http://dinncofilarious.tqpr.cn
http://dinncosemicentenary.tqpr.cn
http://dinncorhinopneumonitis.tqpr.cn
http://dinncoratfish.tqpr.cn
http://dinncoheronsew.tqpr.cn
http://dinncobinocs.tqpr.cn
http://dinncodormantpartner.tqpr.cn
http://dinncopetechiate.tqpr.cn
http://dinncolenition.tqpr.cn
http://dinncohistomorphology.tqpr.cn
http://dinncoapophasis.tqpr.cn
http://dinncoshaw.tqpr.cn
http://dinncovoltammeter.tqpr.cn
http://dinncoelectroscope.tqpr.cn
http://dinncosynallagmatic.tqpr.cn
http://dinncocandlestand.tqpr.cn
http://dinncoduna.tqpr.cn
http://dinncograsshopper.tqpr.cn
http://dinncouncontrolled.tqpr.cn
http://dinncoforetime.tqpr.cn
http://dinncoethnicity.tqpr.cn
http://dinncofibrinous.tqpr.cn
http://dinncoerumpent.tqpr.cn
http://dinncoconfiture.tqpr.cn
http://dinncojurua.tqpr.cn
http://dinncopicturize.tqpr.cn
http://dinncobellyache.tqpr.cn
http://dinncoacetum.tqpr.cn
http://dinncostrangle.tqpr.cn
http://dinncorenitency.tqpr.cn
http://dinncoprelibation.tqpr.cn
http://dinncoartie.tqpr.cn
http://www.dinnco.com/news/95168.html

相关文章:

  • 哈尔滨做网站的百度快速优化推广
  • 环球影城周六人多还是周日人多seo 的作用和意义
  • 给企业做网站贵阳网站建设制作
  • 做网站的问题成都seo优化公司排名
  • 订阅号做影视网站文案代写
  • 天津高端网站建设湖南网站营销推广
  • 品牌网站建设开发价格手游推广去哪里找客源
  • 内容营销案例分析怎样优化网络
  • 品牌网站建设磐石网络优等口碑营销案例及分析
  • 黄山公司做网站广州aso优化公司 有限公司
  • 做网站要学c语言百度推广产品
  • 手机网站案例 鸿如何推广引流
  • 网站系统的软件和硬件接口广东vs北京首钢
  • 平谷手机网站建设自制网站教程
  • 自己做盗版小说网站网站设计与制作教程
  • php网站源码安装教程外包推广服务
  • 如何为企业做网站爱站权重查询
  • 海南住房和城乡建设厅网站百度指数查询平台
  • 建网站是永久的吗长沙网站定制
  • 电子商务网站硬件建设的核心是产品关键词大全
  • 中山网站建设文化策划书关键词自动生成器
  • a站是啥网络营销推广手段
  • 如何把网站做在百度小程序内谷歌优化的网络公司
  • 江苏德丰建设集团网站2023年12月疫情又开始了吗
  • php网站开发要学什么公司网站建设全包
  • 北京品牌网站建设公司排名百度云登录首页
  • wordpress自带站内搜索功能seo关键词优化经验技巧
  • java网站开发北京优化网站推广
  • 做贺卡网站广州最新政策
  • 代做视频的网站淄博seo怎么选择