use cluster.on('fork') for adding forks
This commit is contained in:
parent
7d9730c1c8
commit
14c4788e8c
17
README.md
17
README.md
|
@ -35,9 +35,10 @@ The usage is exactly the same as **master**, no changes necessary.
|
||||||
|
|
||||||
### master
|
### master
|
||||||
|
|
||||||
In the **master**/**standalone** process you will create the real store instance
|
In the **master**/**standalone** process you will create the real store instance.
|
||||||
and then in the you must pass each worker via `addWorker()` so that it signals
|
|
||||||
the worker to create its own rpc-wrapped instance.
|
If you need to manually specify which worker will be enabled for this funcitonality
|
||||||
|
you must set `addOnFork` to `false` and call `addWorker()` manually.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -46,10 +47,12 @@ var cluster = require('cluster');
|
||||||
|
|
||||||
var cstore = require('cluster-store/master').create({
|
var cstore = require('cluster-store/master').create({
|
||||||
name: 'foo-store'
|
name: 'foo-store'
|
||||||
, store: null // use default in-memory store
|
, store: null // use default in-memory store
|
||||||
|
, addOnFork: true // default
|
||||||
});
|
});
|
||||||
|
|
||||||
cstore.addWorker(cluster.fork());
|
// if you addOnFork is set to false you can add specific forks manually
|
||||||
|
//cstore.addWorker(cluster.fork());
|
||||||
|
|
||||||
cstore.then(function (store) {
|
cstore.then(function (store) {
|
||||||
store.set('foo', 'bar');
|
store.set('foo', 'bar');
|
||||||
|
@ -119,11 +122,13 @@ if (cluster.isMaster) {
|
||||||
cstore = require('./master').create({
|
cstore = require('./master').create({
|
||||||
name: 'foo-level'
|
name: 'foo-level'
|
||||||
});
|
});
|
||||||
cstore.addWorker(cluster.fork());
|
|
||||||
cstore.then(function (store) {
|
cstore.then(function (store) {
|
||||||
store.put('foo', 'bar');
|
store.put('foo', 'bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// create as many workers as you need
|
||||||
|
cluster.fork();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue