xy123321 发表于 2017-12-20 16:08:08

StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改

redis.GetDatabase().ScriptEvaluate(LuaScript.Prepare(  

               " local ks = redis.call('hkeys', @hashid) " +  
               " local fkeys = {} " +
  
               " for i=1,#ks do " +
  
               //使用string.find进行匹配操作
  
               "   if string.find(ks, @keypattern) then " +
  
               "      fkeys[#fkeys + 1] = ks " +
  
               "   end " +
  
               " end " +
  
               " for i=1,#fkeys,5000 do " +
  
               "   redis.call('hdel', @hashid, unpack(fkeys, i, math.min(i+4999, #fkeys))) " +
  
               " end " +
  
               " return true "
  
               ),
  
               new { hashid = "hkey", keypattern = "^mykey" });   //keypattern为可使用正则表达式
页: [1]
查看完整版本: StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改