eventvat

Evented, in-process key/value store for Node.js and the browser

Synopsis

Motivation

  • A datastore for small, volitile working sets
  • For processes who do not share data, it reduces unnecessary trips across the process boundary.
  • Portability, works in the browser and on the server.
  • Write to any storage end-point (such as local browser storage, a filesystem or couchdb).

Installation

$npm install eventvat

Usage

Each new instance of EventVat is a hash. There are lots of convenient methods attached to each new instance.

EventVat uses EventEmitter2. Listeners can attached to an EventVat object. An EventVat object can emit and event and a listener will respond. An event has three characteristics, the event name, a listener and an associated data key or wildcard.

  var vat = EventVat();
 
  vat.on('get foo', function(keyvalue) {
 
    console.log('`' + key + '` has the value: `' + value + '`');
  });
 
  vat.set('foo', 'hello, world');
  vat.get('foo');

API

Synonymous with EventEmitter2.prototype.emit

Synonymous with EventEmitter2.prototype.on

Synonymous with EventEmitter2.prototype.removeListener

Expire a key

Delete a key

Determine if a key exists

Set a key's time to live in seconds

Set the expiration for a key as a UNIX timestamp

Find all keys matching the given pattern

Move a key to another database

Inspect the internals of an object

Remove the expiration from a key

Return a random key from the keyspace

Rename a key

Rename a key, only if the new key does not exist

Sort the elements in a list, set or sorted set

Determine the type stored at key

Get the time to live for a key

Append a value to a key

Decrement the integer value of a key by one

Decrement the integer value of a key by the given number

Get the value of a key

Returns the bit value at offset in the string value stored at key

Get a substring of the string stored at a key

Set the string value of a key and return its old value

Increment the integer value of a key by one

Increment the integer value of a key by the given number

Get the values of all the given keys

Set multiple keys to multiple values

Set multiple keys to multiple values, only if none of the keys exist

Set the string value of a key

Sets or clears the bit at offset in the string value stored at key

Set the value and expiration of a key

Set the value of a key, only if the key does not exist

Overwrite part of a string at key starting at the specified offset

Get the length of the value stored in a key

Delete one or more hash fields

Determine if a hash field exists

Get the value of a hash field

Get all the fields and values in a hash

Increment the integer value of a hash field by one

Increment the integer value of a hash field by the given number

Decrement the integer value of a hash field by one

Decrement the integer value of a hash field by the given number

Get all the fields in a hash

Get the number of fields in a hash

Get the values of all the given hash fields

Set multiple hash fields to multiple values

Set the string value of a hash field

Set the value of a hash field, only if the field does not exist

Get all the values in a hash

Dump the current data store into a string

Swap two values

Search within the value of a key

Tests

$npm test

(The MIT License)

Copyright (c) 2010 hij1nx http://www.twitter.com/hij1nx

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE DBSIZEORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.