Created
October 15, 2014 02:13
-
-
Save yukidarake/27806f444af5382e1030 to your computer and use it in GitHub Desktop.
Redisのキーのタイプを集計した時のスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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