redis 127.0.0.1:6379> SCRIPT LOAD "local list=redis.call('KEYS', KEYS[1] .. '*') return (table.getn(list))"
"fdece9fbf98e91fe138eb2fcc5a6f0fbd24c90f9"
redis 127.0.0.1:6379> EVALSHA fdece9fbf98e91fe138eb2fcc5a6f0fbd24c90f9 1 BILL_ACCOUNT_06
(integer) 1640
redis 127.0.0.1:6379>

--------------------------------------------------------------------

功能:多索引记录,set类型存放索引,记录存放在string类型里

SCRIPT LOAD "local list,z,x,y=redis.call('SMEMBERS', KEYS[1]),{} for x,y in ipairs(list) do table.insert(z, redis.call('GET', y)) end return (z)"

EVALSHA 98cf4fd57708c3378215378a16d0f32e2f6c5d40 1 key_Set 

功能:返回key*的数据

SCRIPT LOAD "local list,z,x,y=redis.call('KEYS', KEYS[1] .. '*'),{} for x,y in ipairs(list) do table.insert(z, redis.call('HGETALL', y)) end return (z)"

EVALSHA f2ef5669bef11c60caa5ec8a3139ed3f108540ff 1 U

功能:索引为数值类型的单索引记录集可以放在 Sorted-Sets 类型里,这样也可以用eval进行枚举类的批量数据查询

SCRIPT LOAD "local result,dot,str,i,j,k={},',',KEYS[2],0,0 while true do j=string.find(str, dot,i+1) if nil==j then k=string.sub(str,i+1) table.insert(result,redis.call('zrangebyscore', KEYS[1],k,k)) break end k=string.sub(str,i+1,j-1) table.insert(result,redis.call('zrangebyscore', KEYS[1],k,k)) i=j end return(result)"

EVALSHA f4a12bbcdb685923b04eeab466fa1de751c52c96 2 key_Sorted-Sets  " ,分割的枚举集合"

功能:索引为数值类型的单索引记录集可以放在 Sorted-Sets 类型里,这样也可以用eval进行枚举类的批量数据更新

SCRIPT LOAD "local result,dot,str,i,j,k={},',',KEYS[3],0,0 while true do j=string.find(str, dot,i+1) if nil==j then k=string.sub(str,i+1) table.insert(result,redis.call('zadd', KEYS[1],KEYS[2],k)) break end k=string.sub(str,i+1,j-1) table.insert(result,redis.call('zadd', KEYS[1],KEYS[2],k)) i=j end return(result)"

EVALSHA e9992e80eb06b78433b80ba207d45486c49e690a 3 key_Sorted-Sets  score  " ,分割的枚举集合"

--------------------

SCRIPT LOAD "local result,dot,sKey,sField,iF,jF,sValue,iV,jV={},',',KEYS[1],KEYS[2],0,0,KEYS[3],0,0 while true do jF=string.find(sField, dot,iF+1) jV=string.find(sValue, dot,iV+1) if nil==jF then  table.insert(result,redis.call('HSET', sKey,string.sub(sField,iF+1),string.sub(sValue,iV+1))) break end  table.insert(result,redis.call('HSET', sKey,string.sub(sField,iF+1,jF-1),string.sub(sValue,iV+1,jV-1))) iF=jF iV=jV end return(result)"
EVALSHA f65b5d677cdfdf9fd9a4ec5cf3e9a4fd4a187dc9 3  UUUU 221,222,223 331,332,333

SCRIPT LOAD "local result,dot,sPrefix,sKey,iK,jK,sField,iF,jF,sValue,iV,jV={},',',KEYS[1],KEYS[2],0,0,KEYS[3],0,0,KEYS[4],0,0 while true do jK=string.find(sKey, dot,iK+1) jF=string.find(sField, dot,iF+1) jV=string.find(sValue, dot,iV+1) if nil==jF then  table.insert(result,redis.call('HSET', sPrefix .. string.sub(sKey,iK+1),string.sub(sField,iF+1),string.sub(sValue,iV+1))) break end  table.insert(result,redis.call('HSET', sPrefix .. string.sub(sKey,iK+1,jK-1),string.sub(sField,iF+1,jF-1),string.sub(sValue,iV+1,jV-1))) iK=jK iF=jF iV=jV end return(result)"
EVALSHA d965a30e6524a96b070b3a7ed92ea2b7ff3c2dcd 4 AAAA 111,112,113 221,222,223 331,332,333

对照:

SCRIPT LOAD "local result,dot,dotV,sKey,sField,iF,jF,sValue,iV,jV={},',',',,,,',KEYS[1],KEYS[2],0,0,KEYS[3],-3,0 while true do jF=string.find(sField, dot,iF+1) jV=string.find(sValue, dotV,iV+4) if nil==jF then  table.insert(result,redis.call('HSET', sKey,string.sub(sField,iF+1),string.sub(sValue,iV+4))) break end  table.insert(result,redis.call('HSET', sKey,string.sub(sField,iF+1,jF-1),string.sub(sValue,iV+4,jV-1))) iF=jF iV=jV end return(result)"
EVALSHA eb4c19bfec0498da4901f374c30b7f1b18aacf7a 3  UUUU 221,222,223 331,,,,332,,,,333

SCRIPT LOAD "local result,dot,dotV,sPrefix,sKey,iK,jK,sField,iF,jF,sValue,iV,jV={},',',',,,,',KEYS[1],KEYS[2],0,0,KEYS[3],0,0,KEYS[4],-3,0 while true do jK=string.find(sKey, dot,iK+1) jF=string.find(sField, dot,iF+1) jV=string.find(sValue, dotV,iV+4) if nil==jF then  table.insert(result,redis.call('HSET', sPrefix .. string.sub(sKey,iK+1),string.sub(sField,iF+1),string.sub(sValue,iV+4))) break end  table.insert(result,redis.call('HSET', sPrefix .. string.sub(sKey,iK+1,jK-1),string.sub(sField,iF+1,jF-1),string.sub(sValue,iV+4,jV-1))) iK=jK iF=jF iV=jV end return(result)"
EVALSHA 65e1e8efb1ec004b027cbfb0ba56bb7b27c83479 4 AAAA 111,112,113 221,222,223 331,,,,332,,,,333

--------------------

功能:索引为数值类型的单索引记录集可以放在 Sorted-Sets 类型里,这样也可以用eval进行枚举类的批量数据先查询是否存在,存在任一个则返回,均不存在则进行更新

SCRIPT LOAD "local result,dot,str,i,j,k,n={},',',KEYS[3],0,0,nil,0 while true do j=string.find(str, dot,i+1) if nil==j then if redis.call('zscore', KEYS[1],string.sub(str,i+1))  then n=n+1 end break end if redis.call('zscore', KEYS[1],string.sub(str,i+1,j-1)) then n=n+1 end i=j end if 0~=n then return(n) end i,j=0,0 while true do j=string.find(str, dot,i+1) if nil==j then k=string.sub(str,i+1) table.insert(result,redis.call('zadd', KEYS[1],KEYS[2],k)) break end k=string.sub(str,i+1,j-1) table.insert(result,redis.call('zadd', KEYS[1],KEYS[2],k)) i=j end return(result)"

EVALSHA  5aaecb5a2a17068f78400767a50863f85318c79d 3 key_Sorted-Sets  score  " ,分割的枚举集合"

redis的lua使用(EVALSHA)的更多相关文章

  1. redis之lua脚本

    背景介绍 redis数据库提供了一些管理功能比如 流水线:打包发送多条命令,并在一个回复里面接收所有被执行命令的结果.事务:一次执行多条命令,被执行的命令要么就全部都被执行,要么就一个也不执行.并且事 ...

  2. Redis学习-LUA脚本

    最近在做K线的项目中,需要计算商品的分时数据.为了保证多台机器对同一商品的计算的有序性,所以在Redis中进行计算,同时为了保证在分时数据计算过程的原子性所以使用了LUA脚本,Redis内置了对LUA ...

  3. Redis进阶实践之七Redis和Lua初步整合使用

    一.引言        Redis学了一段时间了,基本的东西都没问题了.从今天开始讲写一些redis和lua脚本的相关的东西,lua这个脚本是一个好东西,可以运行在任何平台上,也可以嵌入到大多数语言当 ...

  4. Redis结合Lua脚本实现高并发原子性操作

    从 2.6版本 起, Redis 开始支持 Lua 脚本 让开发者自己扩展 Redis … 案例-实现访问频率限制: 实现访问者 $ip 在一定的时间 $time 内只能访问 $limit 次. 非脚 ...

  5. Redis进阶实践之七Redis和Lua初步整合使用(转载 7)

    Redis进阶实践之七Redis和Lua初步整合使用 一.引言 Redis学了一段时间了,基本的东西都没问题了.从今天开始讲写一些redis和lua脚本的相关的东西,lua这个脚本是一个好东西,可以运 ...

  6. redis与lua

    内容大纲 redis里使用eval和evalsha redis管理Lua脚本  php里使用redis的lua脚本 在redis里使用lua脚本的好处 1.Lua脚本在Redis中是原子执行的,执行过 ...

  7. Redis 与 Lua Script

    [Redis Script] 1.EVAL script numkeys key [key ...] arg [arg ...] 从 Redis 2.6.0 版本开始,通过内置的 Lua 解释器,可以 ...

  8. redis(6)lua脚本

    一.lua脚本 lua是一种轻量小巧的脚本语言,用标准的C语言编写并以源代码形式开放,其设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能. lua的详细内容你可以参考lua官方网站 ...

  9. .Net Core使用分布式缓存Redis:Lua脚本

    一.前言 运行环境window,redis版本3.2.1.此处暂不对Lua进行详细讲解,只从Redis的方面讲解. 二.Redis的Lua脚本 在Redis的2.6版本推出了脚本功能,允许开发者使用L ...

  10. Redis 实战 —— 14. Redis 的 Lua 脚本编程

    简介 Redis 从 2.6 版本开始引入使用 Lua 编程语言进行的服务器端脚本编程功能,这个功能可以让用户直接在 Redis 内部执行各种操作,从而达到简化代码并提高性能的作用. P248 在不编 ...

随机推荐

  1. 视频最后用使用了function(i,ot)一笔带过,但我看不懂i和ot这2个参数的具体值是怎么获取得到的,能不能说一下参数传递过程?

    使用函数设置文本内容: $(selector).text(function(index,currentcontent)) 参数描述content必需.规定被选元素的新文本内容.注意:  特殊字符会被编 ...

  2. Visual Studio 2015正式版/产品密钥 Win10正式版官方原版ISO镜像下载大全&安装激活教程

    Visual Studio 2015  发行说明: https://visualstudio.com/zh-cn/news/vs2015-vs.aspx Visual Studio  2015 特性简 ...

  3. ListView中item的最外层使用margin属性失效

    参考文章:http://stackoverflow.com/questions/16278159/why-linearlayouts-margin-is-being-ignored-if-used-a ...

  4. ARM开发板挂载U盘

    ARM开发板运行Linux系统后,插入U盘,通过串口打印系统识别到U盘如下: 系统识别U盘盘符为sda4 那么需要挂载后才能操作U盘:挂载命令 mount -t vfat /dev/sda4 /mnt ...

  5. OC基础(7)

    封装 继承基本概念 继承相关特性 多态基本概念 多态的实现 *:first-child { margin-top: 0 !important; } body > *:last-child { m ...

  6. 关于 LimitedConcurrencyLevelTaskScheduler 的疑惑

    1. LimitedConcurrencyLevelTaskScheduler 介绍 这个TaskScheduler用过的应该都知道,微软开源的一个任务调度器,它的代码很简单, 也很好懂,但是我没有明 ...

  7. oracle的sqlldr并行导入表不要加索引

    ORA-26002: Table string has index defined upon it. Cause: Parallel load was specified into a table w ...

  8. jQuery Mask

    <script type="text/javascript" src="/assets/mask/jquery.mask.min.js"></ ...

  9. activity的android:name 设置问题

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com. ...

  10. Android——Runtime类中的freeMemory,totalMemory,maxMemory等几个方法

    maxMemory() 这个方法返回的是java虚拟机(这个进程)能构从操作系统那里挖到的最大的内存,以字节为单位,如果在运行java程序的时 候,没有添加-Xmx参数,那么就是64兆,也就是说max ...