Skip to content

Instantly share code, notes, and snippets.

@yukidarake
Created October 15, 2014 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukidarake/27806f444af5382e1030 to your computer and use it in GitHub Desktop.
Save yukidarake/27806f444af5382e1030 to your computer and use it in GitHub Desktop.
Redisのキーのタイプを集計した時のスクリプト
-- Redis2.8以降ならSCANを使うのが正解だと思われる http://redis.io/commands/scan
-- 動作をブロックしちゃうので本番で使うのは要注意
local map = {}
local ks = redis.call('KEYS', '*')
for i, v in ipairs(ks) do
local key = string.match(v, '.-\-')
map[key] = (map[key] or 0) + 1
end
local result = {}
local i = 1
for k, v in pairs(map) do
if i >= 10 then
break
end
result[i] = string.format("%s %s", k, v)
i = i + 1
end
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment