zoukankan      html  css  js  c++  java
  • redis的lua使用(EVALSHA)

    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  " ,分割的枚举集合"

  • 相关阅读:
    ElEmentUI选择器弹出框定位错乱问题解决(弹出框出现在左上角)
    Element中(Notification)通知组件字体修改(Vue项目中Element的Notification修改字体)
    解决谷歌浏览器设置font-family属性不起作用,(css中设置了font-family:没有用)css字体属性没用
    开发环境Vue访问后端接口教程(前后端分离开发,端口不同下跨域访问)
    nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决
    ssm项目中中文字符乱码
    idea使用PlantUML画类图教程
    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3报错解决
    安装anaconda python时只能安装到默认文件夹&& 安装提示文件夹以存在问题
    生产者消费者代码学习,Producer_Consuner
  • 原文地址:https://www.cnblogs.com/book-gary/p/redis_0001.html
Copyright © 2011-2022 走看看