The following EVAL script should do what you want:
local keys = redis.call('KEYS',KEYS[1])
for i,k in ipairs(keys) do
local res = redis.call('HKEYS',k)
for j,v in ipairs(res) do
if string.find(v,ARGV[1]) then
redis.call('HDEL',k,v)
end
end
end
You need to call it by providing the following parameters:
EVAL <script> 1 prefix:* cc_..
Please note it blocks the Redis event loop until the script is complete, so it can freeze Redis for a while if you have a large number of keys. Atomicity has a price.
Update:
If you don't need the atomicity, then the following script will avoid blocking Redis for too long (but please note, it will still block if you have a huge global number of keys or if one of your hash object is huge: there is no way to avoid this).
./redis-cli keys 'prefix:*' | awk '
BEGIN {
script = "local res = redis.call('\''HKEYS'\'',KEYS[1]); \
for j,v in ipairs(res) do \
if string.find(v,ARGV[1]) then \
redis.call('\''HDEL'\'',KEYS[1],v); \
end \
end"
}
{
printf "EVAL \"%s\" 1 %s cc_..\n", script, $1
}' | ./redis-cli
(tested with bash)