jsredis

0.1.3 • Public • Published

jsredis

Coverage Downloads Downloads npm version node version dependencies dev dependencies License

A lightweight, high performance in-memory database based on redis. Makes use of the latest ES2015 features (such as Map).

Getting Started

Install it via npm:

npm install jsredis

And include in your project:

import Database from 'jsredis';

Usage and Commands

The biggest difference to this and using an actual redis instance is that you can use any type for a hash, field or value, so if you wished you could store functions, classes, arrays, numbers, objects ... etc and not just strings.

All the commands are synchronous, therefore can all be run inline.

BASIC EXAMPLE:

const db = new Database();
 
if (db.hsetnx('hash', 'field', 'value')) {
  console.log(db.hget('hash', 'field')); // logs 'value'
  console.log(db.hkeys('hash')); // logs [ 'field' ]
  console.log(db.hvals('hash')); // logs [ 'value' ]
  console.log(db.hgetall('hash')); // logs [ [ 'field','value' ] ]
  console.log(db.hlen('hash')); // logs 1
  console.log(db.flushdb()); // logs 1
  console.log(db.hlen('hash')); // logs 0
}
 

Currently Available Commands

  • FLUSHDB
  • SET
  • GET
  • SETNX
  • APPEND
  • STRLEN
  • EXISTS
  • TYPE
  • DEL
  • HGET
  • HSET
  • HSETNX
  • HDEL
  • HKEYS
  • HVALS
  • HLEN
  • HEXISTS
  • HGETALL
  • HSTRLEN

Contributing / TODO

If you feel like contributing feel free to fork, make changes and submit a PR.

TODO

  • sets (use es6 Set?)
  • zsets
  • lists (use es6 Set?)
  • expires / ttl etc (thinking lazy key expiry, but would potentially slow other get transactions, suggestions?)
  • tests tests tests \o/
  • docs
  • benchmarks

Benchmarks

Still polishing the benchmark scripts but, initial tests have shown the following:

  • set completes 1 million transactions in ~600-700ms
  • setnx completes 1 million transactions in ~80ms - where exists is true
  • setnx completes 1 million transactions in ~900ms - where exists is false
  • get completes 1 million transactions in ~90ms on a key that doesn't exist
  • get completes 1 million transactions in ~90ms on a key that exists, pretty much the same result as above
  • exists completes 1 million transactions in ~80ms - pretty much same results if key exists or not
  • hset on a single hash for all transactions 1 million transactions in ~700-800ms
  • hset on a on new hash per transaction completes 1 million transactions in ~8000-9000ms

alt text

License

MIT

Package Sidebar

Install

npm i jsredis

Weekly Downloads

1

Version

0.1.3

License

MIT

Last publish

Collaborators