Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
kosyak
Advanced tools
Readme
Distributed in-memory cache store written in Node.js.
All the data is stored on different nodes which are connected between each other with simple TCP/IP JSON-messaging.
Attention! Data consistency is not guaranteed since if one node dies all the data stored in it is gone.
npm install kosyak --save
'use strict'
var assert = require('assert')
var Node = require('kosyak')
var firstNode = new Node({
host: '127.0.0.1',
port: 13390
}).init(/* callback(err) */)
var secondNode = new Node({
master: {
host: '127.0.0.1',
port: 13390
}
}).init(/* callback(err) */)
// after all initialized
firstNode.set('key', 123, function(err, value) {
assert.strictEqual(value, 123)
secondNode.get('key', function(err, value) {
assert.strictEqual(value, 123)
firstNode.stop(/* callback */)
secondNode.stop(/* callback */)
})
})
Base class which provides functionality to work with whole store.
Create Node instance.
Arguments
object
- Client options.
string
- Address or host to bind to.number
- Port to bind to.object
- Address/port of master node.
string
number
object
- Options passed to net.Socket
constructor.object
- Options passed to net.Server
constructor.boolean
- If data should be stored as JSON string. Defaults to false
.function
- Fetch function. Read more about it in Node#get
method description.number
- Delay between attempts to connect remote node (ms). Grows in arithmetic progression. Defaults to 2000
.number
- Max # of attempts to connect to remote node. Defaults to 3
.Iterate through each local entry
Arguments
function
- Iterator. Should accept following arguments: (value, key, entry)
.Get or fetch value by key. Get operation works using following algorithm:
get
request is sent to remote node. Otherwise go to step 3.fetch
function is specified in Node constructor options fetch(key, done)
is called, then value is set locally and other nodes are notified. Otherwise null
is returned.Arguments
string
function
- Callback function.Start server and connect to master node if it's specified in options.
Arguments
function
- Callback function.Remove local entry.
Arguments
string
function
- Callback function.Set value locally and notify other nodes.
Arguments
string
*
- Value to be set.If callback
is specified node requests stats from all the nodes and returnes them as callback
first argument. If not specified stats for node returned.
Arguments
function
- Callback function.Stop node and disconnect from all the remote nodes.
Arguments
function
- Callback function.My friend has a cat called Kosyak. And this cat is crazy. Why not call module so?
FAQs
Distributed in-memory cache written in Node.js.
The npm package kosyak receives a total of 4 weekly downloads. As such, kosyak popularity was classified as not popular.
We found that kosyak demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.