Skip to content

Instantly share code, notes, and snippets.

@itslukej
Created April 11, 2020 00:19
Show Gist options
  • Select an option

  • Save itslukej/eb248ec2fa9ebd63b7df13510cc7cd28 to your computer and use it in GitHub Desktop.

Select an option

Save itslukej/eb248ec2fa9ebd63b7df13510cc7cd28 to your computer and use it in GitHub Desktop.
local shard_id = tonumber(ARGV[3])
local shard_count = tonumber(ARGV[2])
local prefix = 'cache:' .. ARGV[1] .. ':'
local keys = redis.call('keys', prefix .. '*')
local deleted = 0
for i,v in pairs(keys) do
local key = keys[i]
local guild_id = string.sub(key, #prefix + 1)
local guild_shard_id = math.floor((guild_id / 2^22) % shard_count)
if shard_id == guild_shard_id then
deleted = deleted + 1
redis.call('del', key)
end
end
return deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment