0.1.3 • Published 10 years ago
jsredis v0.1.3
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 jsredisAnd 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:
setcompletes1 milliontransactions in~600-700mssetnxcompletes1 milliontransactions in~80ms- where exists is truesetnxcompletes1 milliontransactions in~900ms- where exists is falsegetcompletes1 milliontransactions in~90mson a key that doesn't existgetcompletes1 milliontransactions in~90mson a key that exists, pretty much the same result as aboveexistscompletes1 milliontransactions in~80ms- pretty much same results if key exists or nothseton a single hash for all transactions1 milliontransactions in~700-800mshseton a on new hash per transaction completes1 milliontransactions in~8000-9000ms

License
MIT