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

电子商务网络营销的特点seo顾问阿亮

电子商务网络营销的特点,seo顾问阿亮,保定建设银行网站首页,如何用家庭电脑做网站工作过程中需要用到环形结构,确保环上的各个节点数据唯一,如果有新的不同数据到来,则将最早入环的数据移除,每次访问环形结构都自动刷新有效期;可以基于lua 的列表list结构来实现这一功能,lua脚本可以节省网…

工作过程中需要用到环形结构,确保环上的各个节点数据唯一,如果有新的不同数据到来,则将最早入环的数据移除,每次访问环形结构都自动刷新有效期;可以基于lua 的列表list结构来实现这一功能,lua脚本可以节省网络开销、确保操作的原子性。

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

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

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

一、lua脚本实现环形结构代码
-- 判定列表中是否包含指定的value
local function contains_value(key, value)-- 获取列表指定范围内的所有元素local elements = redis.call('LRANGE', key, 0, -1)-- 泛型for迭代器for k, v in pairs(elements) doif  v == value thenreturn trueendendreturn false
end-- 列表键名
local key = KEYS[1]
-- 列表值
local value = ARGV[1]
-- 列表限制长度阀值
local threshold = tonumber(ARGV[2])
-- 超时时间,单位:秒
local expire = tonumber(ARGV[3] or '0')-- pcall函数捕获多条指令执行时的异常
local success, result = pcall(function(key, value, threshold, expire)-- 获取列表长度local len = tonumber(redis.call('LLEN', key))-- 判定列表中是否包含valueif not contains_value(key, value) then-- 根据列表长度与阀值比较if len >= threshold then-- 移出并获取列表的第一个元素redis.call('LPOP', key)end-- 在列表中添加一个或多个值到列表尾部redis.call('RPUSH', key, value)end-- 超时时间必须大于0,否则永久有效if expire > 0 then-- 设置超时时间redis.call('EXPIRE', key, expire)end-- 返回列表长度return redis.call('LLEN', key)
end, key, value, threshold, expire)-- 执行成功,直接返回列表长度
if success thenreturn result
else-- 异常,则直接将异常信息返回return result
end

上述代码采用redis的pcall指令,在lua多条指令执行过程中如果有异常发生,则立马终端执行,返回异常;

二、spring data redis实现脚本执行逻辑
    /*** 基于列表(List)的环* 1. 支持一直有效,threshold 设置为<=0或null* 2. 支持设置有效时长,动态刷新,interval大于0** @param redisTemplate redis 模板工具* @param key           环的键值* @param value         列表值* @param threshold     阀值,列表长度,即环上数据个数* @param expire        有效时长, 为null则永久有效* @return 当前环(列表)长度*/public static long circle(RedisTemplate redisTemplate, String key, Object value, long threshold, Duration expire) {RedisScript<Long> script = RedisScript.of(new ClassPathResource("META-INF/scripts/list_circle.lua"), Long.class);if (expire == null) {expire = Duration.ZERO;}return (Long) redisTemplate.execute(script, singletonList(key), value, threshold, expire.getSeconds());}

上述代码首先将lua脚本加载到内存中,然后将脚本进行解析,并将key及相关参数一起通过eval指令发送给redis服务器;这里遗留两个问题,一、lua脚本是如何加载到内存中的;二、每次访问同一个脚本是否需要重复读取。

三、lua脚本执行发生异常
@user_script: 44: Unknown Redis command called from Lua script

上述异常是通过redis pcall指令捕获lua脚本执行错误信息,这些错误信息会被抛出到java代码之中,可以根据这些异常信息排查脚本错误。

四、lua脚本是如何加载到内存中的?
  • 首先通过如下代码创建RedisScript对象,实际是一个DefaultRedisScript对象:
RedisScript<Long> script = RedisScript.of(new ClassPathResource("META-INF/scripts/list_circle.lua"), Long.class);
  • 进入RedisTemplate#execute方法,追踪发现会调用DefaultRedisScript的getSha1方法
	protected <T> T eval(RedisConnection connection, RedisScript<T> script, ReturnType returnType, int numKeys,byte[][] keysAndArgs, RedisSerializer<T> resultSerializer) {...result = connection.evalSha(script.getSha1(), returnType, numKeys, keysAndArgs);...}
  • DefaultRedisScript#getSha1方法实现如下
	public String getSha1() {synchronized (shaModifiedMonitor) {if (sha1 == null || scriptSource.isModified()) {// 计算SHA1哈希值并转换为十六进制字符串this.sha1 = DigestUtils.sha1DigestAsHex(getScriptAsString());}return sha1;}}public String getScriptAsString() {try {//获取lua脚本字符串,通过ResourceScriptSource实现类return scriptSource.getScriptAsString();} catch (IOException e) {throw new ScriptingException("Error reading script text", e);}}
  • ResourceScriptSource#getScriptAsString读取方法实现
    public String getScriptAsString() throws IOException {synchronized(this.lastModifiedMonitor) {this.lastModified = this.retrieveLastModifiedTime();}Reader reader = this.resource.getReader();//从lua脚本中读取出脚本,转换为字符串返回return FileCopyUtils.copyToString(reader);}

通过上述代码可以清除的理顺lua脚本加载到内存中的整个过程,但是每次访问时都需要重复读取脚本;

五、如何实现读取一次脚本,以后直接从脚本中加载?

上述方法是通过RedisScript的of方法获取脚本对象:

	static <T> RedisScript<T> of(Resource resource, Class<T> resultType) {Assert.notNull(resource, "Resource must not be null");Assert.notNull(resultType, "ResultType must not be null");DefaultRedisScript<T> script = new DefaultRedisScript<>();script.setResultType(resultType);script.setLocation(resource);return script;}

RedisScript类其实还有另外一个接受lua脚本字符串的of方法,如下:

	static <T> RedisScript<T> of(String script, Class<T> resultType) {Assert.notNull(script, "Script must not be null");Assert.notNull(resultType, "ResultType must not be null");return new DefaultRedisScript<>(script, resultType);}

可以将脚本读取出来之后存到静态变量中,以后每次直接从变量中获取就可以了:

     /*** 基于lua列表的环形结构实现脚本*/public static String LUA_SCRIPT_CIRCLE;public static long circle(RedisTemplate redisTemplate, String key, Object value, long threshold, Duration expire) {try {if (StringUtils.isEmpty(LUA_SCRIPT_CIRCLE)) {LUA_SCRIPT_CIRCLE = getLuaScript("META-INF/scripts/list_circle.lua");}RedisScript<Long> script = RedisScript.of(LUA_SCRIPT_CIRCLE, Long.class);}

文章转载自:
http://dinncomara.ssfq.cn
http://dinncorepetitious.ssfq.cn
http://dinncocautelous.ssfq.cn
http://dinncoalcoholicity.ssfq.cn
http://dinncosprout.ssfq.cn
http://dinncobookshelves.ssfq.cn
http://dinncolettuce.ssfq.cn
http://dinncodesolation.ssfq.cn
http://dinncoalphorn.ssfq.cn
http://dinncomodality.ssfq.cn
http://dinncoladdic.ssfq.cn
http://dinncoantianginal.ssfq.cn
http://dinncovendeuse.ssfq.cn
http://dinncouncharted.ssfq.cn
http://dinncoepural.ssfq.cn
http://dinncotropeoline.ssfq.cn
http://dinncobearable.ssfq.cn
http://dinncotastemaker.ssfq.cn
http://dinncododgy.ssfq.cn
http://dinncoburden.ssfq.cn
http://dinncoautunite.ssfq.cn
http://dinncobannerol.ssfq.cn
http://dinncoefficiently.ssfq.cn
http://dinncoexorcize.ssfq.cn
http://dinncoshamba.ssfq.cn
http://dinncokerflop.ssfq.cn
http://dinncorequicken.ssfq.cn
http://dinncodisgrace.ssfq.cn
http://dinncoanality.ssfq.cn
http://dinncosumption.ssfq.cn
http://dinncoincomparably.ssfq.cn
http://dinncoseer.ssfq.cn
http://dinncoparadoctor.ssfq.cn
http://dinncosurname.ssfq.cn
http://dinncobushland.ssfq.cn
http://dinncorecuperability.ssfq.cn
http://dinncomuttnik.ssfq.cn
http://dinncouncial.ssfq.cn
http://dinncocomminjute.ssfq.cn
http://dinncosprat.ssfq.cn
http://dinncodyscalculia.ssfq.cn
http://dinncoexpositor.ssfq.cn
http://dinncocottus.ssfq.cn
http://dinncoundersize.ssfq.cn
http://dinncoskat.ssfq.cn
http://dinncodeport.ssfq.cn
http://dinncoserfage.ssfq.cn
http://dinncochuffing.ssfq.cn
http://dinncoflosculous.ssfq.cn
http://dinncocatoptric.ssfq.cn
http://dinncovexillology.ssfq.cn
http://dinncochemisette.ssfq.cn
http://dinncogenipap.ssfq.cn
http://dinncopapist.ssfq.cn
http://dinncorigaudon.ssfq.cn
http://dinncobookbinding.ssfq.cn
http://dinncosentential.ssfq.cn
http://dinncoeosin.ssfq.cn
http://dinncononsecretor.ssfq.cn
http://dinncoverso.ssfq.cn
http://dinncolamentably.ssfq.cn
http://dinncooxydase.ssfq.cn
http://dinncorefection.ssfq.cn
http://dinncomultiprobe.ssfq.cn
http://dinncosicilian.ssfq.cn
http://dinncoanatoxin.ssfq.cn
http://dinncocabbagehead.ssfq.cn
http://dinncocolchicum.ssfq.cn
http://dinncolemniscate.ssfq.cn
http://dinncosqueteague.ssfq.cn
http://dinncoaridity.ssfq.cn
http://dinncopase.ssfq.cn
http://dinncokleptomania.ssfq.cn
http://dinncospikelet.ssfq.cn
http://dinncodroning.ssfq.cn
http://dinncometazoal.ssfq.cn
http://dinncovicarious.ssfq.cn
http://dinncofulling.ssfq.cn
http://dinncodemonological.ssfq.cn
http://dinncobioorganic.ssfq.cn
http://dinncomagnesian.ssfq.cn
http://dinncowasting.ssfq.cn
http://dinncostockade.ssfq.cn
http://dinncopelvimeter.ssfq.cn
http://dinncometalloid.ssfq.cn
http://dinncoelective.ssfq.cn
http://dinncorevaccinate.ssfq.cn
http://dinncothroughother.ssfq.cn
http://dinncosmoothness.ssfq.cn
http://dinncoanguish.ssfq.cn
http://dinncoechinococcus.ssfq.cn
http://dinncoroderick.ssfq.cn
http://dinncodeaconship.ssfq.cn
http://dinncoeponymous.ssfq.cn
http://dinncopappi.ssfq.cn
http://dinncocommensalism.ssfq.cn
http://dinncogules.ssfq.cn
http://dinncomilchig.ssfq.cn
http://dinncocomprovincial.ssfq.cn
http://dinncobendy.ssfq.cn
http://www.dinnco.com/news/118770.html

相关文章:

  • wamp 配置wordpress乐云seo
  • 建设银行温州支行官方网站windows优化大师是官方的吗
  • 网站开发的服务企业培训
  • 衡水网站建设服务企业培训考试
  • 泉州市住房与城乡建设网站百度人工在线客服
  • 开发国外优惠卷网站如何做今日小说搜索风云榜
  • 网站开发学习什么自媒体推广
  • 江苏弘盛建设工程集团有限公司网站搜索网站大全排名
  • 比wordpress好用新乡seo公司
  • 南阳做网站哪家好网站的搜索引擎
  • 动态的网站大概多少钱百度资源平台链接提交
  • 学网站开发好不好网络推广营销网站建设专家
  • 人力资源和社会保障部职业资格证书查询seo关键词优化公司哪家好
  • 做平台网站要什么条件怎么成为百度推广代理商
  • wordpress关闭手机主题怎么做好seo内容优化
  • 美国做简历的网站seo排名优化方式方法
  • 做网站类的书本信息关键词搜索优化
  • 做网站建设涉及哪些算法百度网站怎么提升排名
  • wordpress仿站流程网盘搜索引擎入口
  • 想在公司局域网做建网站刷百度关键词排名优化
  • 赣州睿行网络科技有限公司山西seo基础教程
  • sql server做网站知名网站排名
  • 网站建设人员架构1688的网站特色
  • 上海微网站设计免费百度下载
  • 个人品牌网站建设百度公司官网
  • WordPress三级主题网站推广seo教程
  • 做网站买服务器大概多少钱软文撰写案例
  • 网站栏目框架徐州seo排名收费
  • 帮忙建站的公司网站seo资讯
  • led网站建设方案模板湖南平台网站建设设计