Created
January 26, 2015 08:48
-
-
Save alexanderscott/8abc6557244eb86cafad to your computer and use it in GitHub Desktop.
Redis Lua script to get size of multiple ZSETs
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
| -- @desc: Get size of multiple ZSETs | |
| -- @usage: redis-cli EVAL "$(cat MZCARD.lua)" N <zset1> <zset2> ... <zsetN> | |
| -- @return: list of sizes | |
| local function MZCARD(keys) | |
| local sizes = {} | |
| for _,key in ipairs(keys) do | |
| table.insert(sizes, redis.call("ZCARD", key)) | |
| end | |
| return sizes | |
| end | |
| --[[ @TEST | |
| redis.call("ZADD", "test_zset1", 5, "five", 6, "six") | |
| redis.call("ZADD", "test_zset2", 7, "seven", 8, "eight", 9, "nine") | |
| local mzcard = MZCARD({"test_zset1", "test_empty", "test_zset2"}) | |
| assert(mzcard[1] == 2) | |
| assert(mzcard[2] == 0) | |
| assert(mzcard[3] == 3) | |
| redis.call("DEL", "test_zset1", "test_zset2") | |
| --]] | |
| return MZCARD(KEYS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment