-
Notifications
You must be signed in to change notification settings - Fork 21
Change API
The data-system allows your application to keep real-time state of the data through a pub-sub api. Redis is used as the pub-sub connecter.
The available channels are as follow :
Channel Msg Description
[docType].create id Fired when a doc of given docType is created
[docType].update id Fired when a doc of given docType is updated
[docType].delete id Fired when a doc of given docType is deleted through the data-system
null.create id Fired when a doc with no docType is created
null.update id Fired when a doc with no docType is updated
null.delete id Fired when a doc with no docType is deleted through the data-system
delete id Fired when a doc is deleted (even if not through the data-system)
NB : when a doc is deleted from the data-system, both docType.delete
and delete
are fired.
In your application, simply do :
coffeescript redis = require('redis').createClient() redis.on 'pmessage', (pattern, event, id) -> #event = "doctype.operation" #id = document's id #pattern = [pattern] #see below redis.psubscribe '[pattern]'
[pattern] can use a wildcard *
: for example *.create
, note.*
, *
.
You can psubscribe to several patterns.
Let's say we want to be informed of every note operation and task suppression
redis.on 'pmessage', (pattern, event, id) ->
if pattern is 'note.*'
if event is 'note.create'
Note.find id, (err, note) ->
# do stuff with note
else if event is 'task.delete'
# Task with id = id have been deleted
redis.psubscribe 'note.*'
redis.psubscribe 'task.delete'
You can also simply proxy to a socket.io server for real time client update
redis.on 'pmessage', (pattern, event, id) ->
io.sockets.emit event, id
redis.psubscribe 'note.*'