1.0.1 • Published 11 years ago

repred v1.0.1

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

repred

Insanely simple data replication.

<img src=https://secure.travis-ci.org/'Dominic Tarr'/replicated-reduce.png?branch=master>

Example

pass in a reduce like function that merges an update into the node's collection.

var repred = require('repred')

var rr = repred(function (collect, update) {
  var change = []
  update.forEach(function (name) {
    if(!~collect.indexOf(name)) {
      change.push(name)
      collect.push(name)
    }
    return change
  })
}, [])

the function must also return a change object, which is just the changes which actually applied. if changes is non-empty, (not [] or {}) then that update will be sent across the wire to any connected nodes.

  1. write a map-reduce that is commutative and idempotent.
  2. distribute them, and connect them via streams.
  3. Eventual Consistency!

connect like this:

rs1 = rr1.createStream()
rs2 = rr2.createStream()

rs1.pipe(rs2).pipe(rs1)

or, through a text stream...

var serializer = require('stream-serializer')
var net = require('net')

var rr1 = reprep(...)

net.createServer(function (stream) {
  stream.pipe(
    serializer(rr1.createStream())
  ).pipe(stream)
}).listen(PORT)

var rr2 = reprep(...)

var stream = net.connect(PORT)
stream.pipe(
    serializer(rr2.createStream)
  ).pipe(stream)

License

MIT

1.0.1

11 years ago

1.0.0

11 years ago

0.1.0

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago