haraka-nosql 0.4.4
Install from the command line:
Learn more about npm packages
$ npm install @haraka/haraka-nosql@0.4.4
Install via package.json:
"@haraka/haraka-nosql": "0.4.4"
About this version
[![Build Status][ci-img]][ci-url] [![Coverage Status][cov-img]][cov-url]
Store stuff in memory-backed objects, smartly.
var NoSQL = require('haraka-nosql');
var nosql = new NoSQL('myindex', {
storage: 'redis', // or 'ram' or 'ssc'
expire: 10, // minutes
});
Exports the following functions:
nosql.set('foo', 'bar', function (err, result) {
if (err) {
// error handling code
return;
}
// do fun stuff with result
});
You're confident it'll work out? Skip the callback, it's optional. For all of these methods.
nosql.set('foo', 'bar'); // going commando
nosql.get('foo', function (err, result) {
if (err) { return; }
// result == 'bar' (because that's what we set it to)
});
nosql.del('foo', function (err, result) {
if (err) { return; }
// result == 1 (# of objects keys deleted)
});
nosql.incrby('my_counter', 1, function (err, result) {
if (err) { return; }
// result == 1 (it was undef, now it's initialized to 1)
});
nosql.incrby('my_counter', 2); // breezy!
// now my_counter == 3 (increment 1 with 2 and math!)
nosql.reset();
// all your keys are belong to /dev/null
- simple
- no dependencies
- Data disappears when Haraka is restarted.
- Not shared across hosts
- With cluster, worker processes share no data. Therefore, each worker process has a partial (incomplete) view of the state data.
- When running with cluster,
nosql
attempts to load strong-store-cluster, which stores data in the master worker.
- All Haraka processes share a single RAM backed data store.
- There's no "reset" operation. Instead, keys expire after 10 minutes (edit
config/nosql.ini [cluster]expire
to alter. This is great for features such as concurrency or brute-force auth tracking.
- disk backed RAM storage
- same view across Harka master & worker processes
- persistence across Haraka & server reboots
- network service, can be shared by many hosts
sed -i.bak -e 's/; backend=redis/backend=redis/' /my/haraka/config/nosql.ini
$EDITOR config/nosql.ini
Edit the settings in the [redis] section.
When Redis is configured, the redis connection is exported as nosql.redis
. Use it like so:
var nosql = require('haraka-nosql');
var redis = nosql.redis;
redis.multi()
.hget('something')
.get('else')
.exec(function (err, res) {
});
Refer to the excellent Redis command docs
Collisions are only possible within your namespace. Each caller of nosql
automatically gets its own namespace. In RAM, each namespace is a JS object, rather like this:
{
karma: {
key: val,
key2: val2,
},
limit: {
key: val,
key2: val2,
}
}
In Strong Store Cluster, each caller gets its own collection.
In Redis, get|del|incrby operations are mapped to their hash equivalents (hget, hdel, hincrby).
[ci-img]: [ci-url]: https://travis-ci.org/haraka/haraka-nosql [cov-img]: https://coveralls.io/repos/haraka/haraka-nosql/badge.png [cov-url]: https://coveralls.io/r/haraka/haraka-nosql
Details
- haraka-nosql
- haraka
- over 2 years ago
- MIT
- 7 dependencies
Assets
- haraka-nosql-0.4.4-npm.tgz
Download activity
- Total downloads 0
- Last 30 days 0
- Last week 0
- Today 0