Skip to content

Instantly share code, notes, and snippets.

@alexanderscott
Created January 26, 2015 08:50
Show Gist options
  • Select an option

  • Save alexanderscott/cd0e43763133be27d046 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderscott/cd0e43763133be27d046 to your computer and use it in GitHub Desktop.
Redis Lua script to publish a message to all SET member channels
-- @desc: Publish a message to all SET member channels
-- @usage: redis-cli EVAL "$(cat SPUBLISH.lua)" 1 <setKey> <message>
-- @return: number of SET member channels
local function SPUBLISH(key, msg)
local members = redis.call("SMEMBERS", key)
for _,member in ipairs(members) do
redis.call("PUBLISH", member, msg)
end
return #members
end
return SPUBLISH(KEYS[1], ARGV[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment