Skip to content

Instantly share code, notes, and snippets.

@paulerickson
Last active November 20, 2017 23:32
Show Gist options
  • Save paulerickson/15c97e2de61e5118b8778ebfcfd24cdd to your computer and use it in GitHub Desktop.
Save paulerickson/15c97e2de61e5118b8778ebfcfd24cdd to your computer and use it in GitHub Desktop.
Removes members from set if no corresponding key can be found (assuming "widgets" / "widget:99" naming convention)
local collectionKey = KEYS[1].."s"
local members = redis.call("smembers", collectionKey)
for _, id in ipairs(members) do
if redis.call("exists", KEYS[1]..":"..id) == 0 then
redis.call("srem", collectionKey, id)
end
end
return redis.call("scard", collectionKey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment