API ReferencePub/Sub
Publish
Publish a message to a Redis channel
Syntax
Redix.Publish(channel, message)Parameters
Prop
Type
Returns
Prop
Type
Examples
-- Publish player join event
local event = json.encode({
type = 'join',
playerId = playerId,
name = GetPlayerName(playerId),
timestamp = os.time()
})
Redix.Publish('events:player', event)
-- Broadcast notification
Redix.Publish('notifications:global', 'Server restart in 5 minutes!')
-- Cross-resource communication
Redix.Publish('resource:inventory', json.encode({
action = 'update',
playerId = playerId,
items = items
}))Use Cases
Multi-Server Synchronization
-- Server 1: Publish event
Redix.Publish('servers:sync', json.encode({
server = GetConvar('sv_hostname', 'Unknown'),
event = 'player_banned',
playerId = playerId
}))
-- Server 2: Receive and process
Redix.Subscribe('servers:sync', function(message)
local data = json.decode(message)
if data.event == 'player_banned' then
BanPlayer(data.playerId)
end
end)