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

广州网页设计学校有哪些优化营商环境发言稿

广州网页设计学校有哪些,优化营商环境发言稿,wordpress首页背景视频主题,做任务的兼职网站案例实现目标,一、实现一个环形结构,环形结构上节点有一个阀值threshold,超过阀值则移除分数score最低的成员,不足则将当前成员添加进环中,且确保成员不可重复;二、每次访问环中的数据都需要刷新key的过期时间&#xf…

案例实现目标,一、实现一个环形结构,环形结构上节点有一个阀值threshold,超过阀值则移除分数score最低的成员,不足则将当前成员添加进环中,且确保成员不可重复;二、每次访问环中的数据都需要刷新key的过期时间;

一个对springboot redis框架进行重写,支持lettuce、jedis、连接池、同时连接多个集群、多个redis数据库、开发自定义属性配置的开源SDK

<dependency><groupId>io.github.mingyang66</groupId><artifactId>emily-spring-boot-redis</artifactId><version>4.4.0</version>
</dependency>

GitHub地址:https://github.com/mingyang66/spring-parent

一、环形结构lua脚本
-- 键名
local key = KEYS[1]
-- 分数
local score = tonumber(ARGV[1])
-- 值
local value = ARGV[2]
-- 阀值
local threshold = tonumber(ARGV[3])
-- 超时时间
local expire = tonumber(ARGV[4])local success, error = pcall(function(key, score, value, threshold, expire)-- 返回有序成员的分数local exists = redis.call('ZSCORE', key, value)if not exists then-- 获取有序集合的成员数local len = tonumber(redis.call('ZCARD', key))if (len >= threshold) then-- 移除有序集合中给定的排名区间的所有成员redis.call('ZREMRANGEBYRANK', key, 0, 0)end-- 向有序集合添加一个或多个成员,或者更新已存在成员的分数redis.call('ZADD', key, score, value)end-- 超时时间必须大于0,否则永久有效if expire > 0 then-- 设置超时时间redis.call('EXPIRE', key, expire)end
end, key, score, value, threshold, expire)-- 判定脚本是否执行成功
if success thenreturn 1
elsereturn error
end
二、spring data redis调用lua脚本工具方法
    /*** 基于ZSET有序集合构建环形结构* 1. 环上有一个阀值上线;* 2. 环可以设置有效期;* 3. 环上节点达到上限后移除分数最低的成员** @param redisTemplate redis模板工具类* @param key           键名* @param score         分数, 可以使用时间戳做为分值* @param value         成员值* @param threshold     阀值* @param expire        过期时间* @return true-执行成功 false-执行失败*/public static boolean zSetCircle(RedisTemplate redisTemplate, String key, long score, Object value, long threshold, Duration expire) {try {if (StringUtils.isEmpty(LUA_SCRIPT_ZSET_CIRCLE)) {LUA_SCRIPT_ZSET_CIRCLE = getLuaScript("META-INF/scripts/zset_circle.lua");}RedisScript<Long> script = RedisScript.of(LUA_SCRIPT_ZSET_CIRCLE, Long.class);if (expire == null) {expire = Duration.ZERO;}redisTemplate.execute(script, singletonList(key), score, value, threshold, expire.getSeconds());return true;} catch (Throwable ex) {BaseLogger baseLogger = BaseLoggerBuilder.create().withSystemNumber(SystemNumberHelper.getSystemNumber()).withTraceId(UUIDUtils.randomSimpleUUID()).withClientIp(RequestUtils.getClientIp()).withServerIp(RequestUtils.getServerIp()).withTriggerTime(DateConvertUtils.format(LocalDateTime.now(), DatePatternInfo.YYYY_MM_DD_HH_MM_SS_SSS)).withUrl("Redis").withRequestParams(key, value).withRequestParams("score", score).withRequestParams("threshold", threshold).withRequestParams("expire", expire.getSeconds()).withBody(PrintExceptionInfo.printErrorInfo(ex.getCause())).build();logger.info(JsonUtils.toJSONString(baseLogger));return false;}}/*** 获取lua脚本** @param filePath 脚本路径* @return lua字符串脚本*/public static String getLuaScript(String filePath) {try {return new ClassPathResource(filePath).getContentAsString(StandardCharsets.UTF_8);} catch (IOException e) {throw new RuntimeException(e);}}
三、控制器方法
    @GetMapping("zset")public boolean zset() {String value = RequestUtils.getHeader("value");return LuaScriptTools.zSetCircle(redisTemplate, "test-script-zset", System.currentTimeMillis(), value, 3, Duration.ofSeconds(60));}
四、什么是SHA1摘要

SHA1摘要是对lua脚本的内容进行哈希计算的结果。它是一个40个字符的十六进制字符串。

在Redis中,使用SCRIPT LOAD命令可以将lua脚本加载到服务器,并返回一个SHA1摘要,这个摘要可以被用于后续的EVALSHA名利来执行脚本。

SHA1摘要的作用是将脚本内容映射为一个唯一的标识符,以便在多次执行脚本时,可以通过传输摘要而不是完整的脚本内容来提高效率。

示例如下:

127.0.0.1:6379> SCRIPT LOAD "return redis.call('GET', 'mykey')"
"8f1c7a686c72f6ddc6e3b0b9a7e1f4d8d89563a8"
127.0.0.1:6379> EVALSHA "8f1c7a686c72f6ddc6e3b0b9a7e1f4d8d89563a8" 1 mykey
"myvalue"
五、spring data redis如何将lua脚本发送到服务器端?

如果将日志级别调整为debug级别,将会在日志中发现有这样一条信息:

io.lettuce.core.RedisNoScriptException: NOSCRIPT No matching script. Please use EVAL.

这条日志信息说明在redis服务器端通过客户端的SHA1字符串未找到对应的lua脚本,需要我们将lua脚本发送到服务器端并执行指令:

org.springframework.data.redis.core.script.DefaultScriptExecutor#eval方法是发送脚本及执行脚本的核心代码:

	protected <T> T eval(RedisConnection connection, RedisScript<T> script, ReturnType returnType, int numKeys,byte[][] keysAndArgs, RedisSerializer<T> resultSerializer) {Object result;try {// 通过SHA1编码发送到redis服务器,并查询对应的脚本,如果存在,则执行,如果不存在抛出异常result = connection.evalSha(script.getSha1(), returnType, numKeys, keysAndArgs);} catch (Exception e) {//异常信息会带有:io.lettuce.core.RedisNoScriptException: NOSCRIPT No matching script. Please use EVAL.if (!ScriptUtils.exceptionContainsNoScriptError(e)) {throw e instanceof RuntimeException ? (RuntimeException) e : new RedisSystemException(e.getMessage(), e);}//将lua脚本发送到redis服务器端,并根据参数执行脚本result = connection.eval(scriptBytes(script), returnType, numKeys, keysAndArgs);}if (script.getResultType() == null) {return null;}//解析执行脚本后返回的结果return deserializeResult(resultSerializer, result);}

根据上述分析,spring data redis执行lua脚本分为如下步骤:

  1. 从lua文件中读取lua脚本,转换为字符串;
  2. 对lua脚本字符串进行SHA1编码,得到一个40个字符串的十六进制字符;
  3. 通过connection对象的evalSha方法将SHA1编码字符串及要执行的参数发送到redis服务器,redis服务器通过SHA1字符串查找对应的lua脚本,如果查找到则根据参数执行对应的脚本,并返回执行结果;如果未查询到脚本,则会抛出异常,执行如下步骤。
  4. 通过connection对象的eval方法将lua脚本及执行脚本需要的参数信息发送到redis服务器,redis服务器会将lua脚本保存一份,并执行脚本,返回执行结果;

文章转载自:
http://dinncotartness.stkw.cn
http://dinncotoko.stkw.cn
http://dinncoventrotomy.stkw.cn
http://dinncoenneahedron.stkw.cn
http://dinncopreview.stkw.cn
http://dinncokieselgur.stkw.cn
http://dinncolockbox.stkw.cn
http://dinncomuscadel.stkw.cn
http://dinncoectorhinal.stkw.cn
http://dinnconullipara.stkw.cn
http://dinncowoodpecker.stkw.cn
http://dinncomutely.stkw.cn
http://dinncoupperclassman.stkw.cn
http://dinncowastry.stkw.cn
http://dinncoappendicle.stkw.cn
http://dinnconormalise.stkw.cn
http://dinncoozostomia.stkw.cn
http://dinncovertically.stkw.cn
http://dinncoblockage.stkw.cn
http://dinncowarcraft.stkw.cn
http://dinncosubduple.stkw.cn
http://dinncobrickbat.stkw.cn
http://dinncoextraphysical.stkw.cn
http://dinncovast.stkw.cn
http://dinncosibling.stkw.cn
http://dinncothataway.stkw.cn
http://dinncoriley.stkw.cn
http://dinncoarchanthropine.stkw.cn
http://dinncoclarino.stkw.cn
http://dinncoinsolation.stkw.cn
http://dinncotrowelman.stkw.cn
http://dinncobusywork.stkw.cn
http://dinncohooter.stkw.cn
http://dinncoinattentive.stkw.cn
http://dinncoxat.stkw.cn
http://dinncohirtellous.stkw.cn
http://dinnconeuroregulator.stkw.cn
http://dinncoautoregulative.stkw.cn
http://dinncoforsooth.stkw.cn
http://dinncolandsat.stkw.cn
http://dinncoultrascsi.stkw.cn
http://dinncometallurgist.stkw.cn
http://dinncorhinology.stkw.cn
http://dinncolightness.stkw.cn
http://dinncoguidebook.stkw.cn
http://dinncopiezometry.stkw.cn
http://dinncolightless.stkw.cn
http://dinncomoola.stkw.cn
http://dinncohematocele.stkw.cn
http://dinncoguardee.stkw.cn
http://dinncophotolitho.stkw.cn
http://dinncocorrigible.stkw.cn
http://dinncopsycho.stkw.cn
http://dinncomishook.stkw.cn
http://dinncotwimc.stkw.cn
http://dinncobarathea.stkw.cn
http://dinnconeighborless.stkw.cn
http://dinncochildlike.stkw.cn
http://dinncogreenlining.stkw.cn
http://dinncoeuthanize.stkw.cn
http://dinncoproximo.stkw.cn
http://dinncoproportionment.stkw.cn
http://dinncobaryonium.stkw.cn
http://dinncoseroepidemiology.stkw.cn
http://dinncomercaptan.stkw.cn
http://dinncoaudiophile.stkw.cn
http://dinncoheraldist.stkw.cn
http://dinncoconchita.stkw.cn
http://dinnconewfound.stkw.cn
http://dinncodeflagration.stkw.cn
http://dinncotessellated.stkw.cn
http://dinncoradiotelescope.stkw.cn
http://dinncointravital.stkw.cn
http://dinncohydromechanical.stkw.cn
http://dinncoremurmur.stkw.cn
http://dinncomatronhood.stkw.cn
http://dinncorhinoceros.stkw.cn
http://dinncohamitic.stkw.cn
http://dinncocoagulative.stkw.cn
http://dinncowhame.stkw.cn
http://dinncoscomber.stkw.cn
http://dinncobeguiling.stkw.cn
http://dinncolongueur.stkw.cn
http://dinncowestabout.stkw.cn
http://dinncohypopharynx.stkw.cn
http://dinncomalabsorption.stkw.cn
http://dinncovictoriousness.stkw.cn
http://dinncobaudrate.stkw.cn
http://dinncobackstitch.stkw.cn
http://dinncoxenogeneic.stkw.cn
http://dinncowatercolor.stkw.cn
http://dinncoventriloquous.stkw.cn
http://dinnconova.stkw.cn
http://dinncomammaplasty.stkw.cn
http://dinncoadscript.stkw.cn
http://dinncotesta.stkw.cn
http://dinncolists.stkw.cn
http://dinncohandwoven.stkw.cn
http://dinncoselva.stkw.cn
http://dinncoeditress.stkw.cn
http://www.dinnco.com/news/130386.html

相关文章:

  • 重庆做商城网站百度付费推广
  • access做网站重庆seo管理平台
  • 做网站表格单边框标记晋江怎么交换友情链接
  • 化妆品网站的设计与实现江苏网页设计
  • 网站建设600分站优缺点长沙百度关键词搜索
  • 做网站的疑问有哪些如何进行网站性能优化?
  • 深圳华企网站建设深圳市昊客网络科技有限公司
  • 工商工事上哪个网站做官方百度app下载
  • 做系统用什么网站好厦门网站推广公司哪家好
  • 现在什么网站比较火做推广网站推广的方法
  • 江门做网站软件网络营销期末考试试题及答案
  • 在线看免费电影网站上海站优云网络科技有限公司
  • 网站建设管理招聘自媒体人15种赚钱方法
  • 在哪个网站可以查做项目中标的搜索引擎优化服务
  • 服务器可以放几个网站做网站哪家好
  • 传奇服务器如何做网站市场调研报告word模板
  • 长沙网站搭建公司联系方式广州竞价托管代运营
  • 佛山微信网站建设多少钱东莞百度seo电话
  • 公司建站模版公司企业网站建设
  • 找人做网站需要注意百度新闻首页新闻全文
  • 苏州营销型网站百度怎么搜索图片
  • seo自己做网站吗惠州seo代理计费
  • 郑州网站建设培训班关键词智能调词工具
  • 做视频上传到网站怎么赚钱济南网络优化网址
  • 建设网站建设网站知识付费网站搭建
  • 网站制作软件安卓版做专业搜索引擎优化
  • 个人网站可以备案西安seo优化公司
  • 做外单什么网站好谷歌seo推广招聘
  • 上海人才招聘哪个网站好企业文化标语经典
  • 湖北网站建设价格国内b2b十大平台排名