Monday, 15 July 2013

lua - delete redis hash values in bulk based on the hash key name -


In a similar fashion, but the solution requires the hash rather than plain key:

A I bunch like the hash with the prefix "prefix:"

a key way down each hash: "cc_XX", where "XX" is a two-letter code.

I need some way to loop through all the radishes hashes and how to remove all the cc_f all keys, how to do it and to find a clear / lua method (either together not good).

Any advice

The following should:

 For the local keys = 'redis.call' ('keys', key [1]), I in the IP (keys) local res = redis.call ('HKEYS', K), for j, in v Res) if the string.find (v, ARGV [1]) then redis.call ('HDE', K, V) end end term   

call it by providing you the following parameters To do: Evil & lt; Script & gt; 1 prefix: * cc_ ..

Please note that until the script completes, the Recon event blocks the loop, so it can freeze Redis for a while if you have large The number of keys in the atom has pricing.

Update:

If you do not need atomicity, then the following script will avoid blocking Redis for a very long time (but please note If you have keys in large numbers or if you have a hash object larger: there is no way to avoid this).

  ./ redis-cli key 'prefix: *' | Awk 'BEGIN {script = "local res = redis.call (' \ '' HKEYS '\', key [1]); \ to ipairs (res) in J, V for \ string if string.find (v, ARGV [1]) then \ redis.call ('\' 'HDEL' \ ', key [1], V); \ end \ end "} {printf" Evil \ "% s \" 1% scc_ .. \ N ", script, $ 1} '| ./redis-cli   

(tests with Bash)

No comments:

Post a Comment