jsredis
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'));
console.log(db.hkeys('hash'));
console.log(db.hvals('hash'));
console.log(db.hgetall('hash'));
console.log(db.hlen('hash'));
console.log(db.flushdb());
console.log(db.hlen('hash'));
}
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 truesetnx
completes 1 million
transactions in ~900ms
- where exists is falseget
completes 1 million
transactions in ~90ms
on a key that doesn't existget
completes 1 million
transactions in ~90ms
on a key that exists, pretty much the same result as aboveexists
completes 1 million
transactions in ~80ms
- pretty much same results if key exists or nothset
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
License
MIT