Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clusterdb

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clusterdb

In-memory persistence for Node.js clustering across workers.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

clusterdb

In-memory persistence for Node.js clustering across workers.

Usage

Master

cluster = require 'cluster'
cpus = require('os').cpus().length

Require the master cdb instance.

cdb = require('../').master

For the 0.0.1 release, creating a data model is required. You then reference these keys elsewhere.

cdb.init
  users: { }

Create some children (giggles).

if cluster.isMaster

  i = 0 
  cluster.setupMaster 
    exec: './child.litcoffee'

  while i < cpus
    proc = cluster.fork()
    i++

  cluster.on 'fork', (worker) -> 
    
    console.log "Forked server worker #{worker.process.pid}"

Let ClusterDB know about the child.

    cdb.addChild worker

  cluster.on 'exit', (worker, code, signal) -> console.log "Server worker died #{worker.process.pid}"

Child

Require and init.

cdb = require('../').child

cdb.init()

Create a dummy user.

user = 
  id: process.pid 
  name: "JohnQ #{process.pid}"

All actions are async.

upsert

cdb.upsert 'users', user, () -> 

fetch

cdb.fetch 'users', user.id, (user) -> 
    

destroy

cdb.destroy 'users', user.id, () ->

Sanity

For the 0.0.1 release, callbacks are overwritten:

cdb.fetch 'users', user.id, (user) -> # Won't return.
cdb.fetch 'users', user.id, (user) -> # Won't return.
cdb.fetch 'users', user.id, (user) -> # Returns.

Keywords

FAQs

Package last updated on 11 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc