API ReferencePub/Sub
Subscribe
Subscribe to a Redis channel
Syntax
Redix.Subscribe(channel, callback)Parameters
Prop
Type
Returns
Prop
Type
Examples
-- Subscribe to player events
Redix.Subscribe('events:player', function(message)
local data = json.decode(message)
print('Event:', data.type, 'Player:', data.playerId)
if data.type == 'join' then
HandlePlayerJoin(data.playerId)
elseif data.type == 'leave' then
HandlePlayerLeave(data.playerId)
end
end)
-- Subscribe to notifications
Redix.Subscribe('notifications:global', function(message)
TriggerClientEvent('showNotification', -1, message)
end)The callback will be invoked every time a message is published to the channel.