tinycbor-redis v0.0.0
Node.js Addon for TinyCBOR with Redis Support
tinycbor-redis is a NodeJS addon that combines use of CPP_Redis with the C based tinyCBOR library. With this addon, you can directly store and retrieve data from a Redis server connection with under-the-hood CBOR serialization and deserialization of passed in data.
Performance
Benchmarks are curerntly in progress and will be included as soon as completed.
Usage
This module provides the following methods:
flushDb(), no arguments, clears redis server currently connected todisconnect(), no arguments, terminates connection to current redis serverhset(), requires a string:key, Arraystring:field, any:value, writes data to serverhget(), requires a string:key, Arraystring:field, retrieves value mapped tofieldhgetall(), requires a string:key, retrieves all field-value pairs stored tokeyhdel(), requires a string:key, Arraystring:field, removesfieldand value stored tofieldfrom serverhscan(), requires a string:key, Arraystring:field, retrieves all field-value pairs corresponding tofielddel(), requires a string:key, removes all data stored tokeyfrom serverdeleteAll(), requires a string:key, Arraystring:field, removes all subfields offield,fieldincludedparsePath(), requires a concatenated CBOR encoded stream (e.g. x61ax61bx62c), returns array of parsed keys (e.g. 'a', 'b', 'c'), useful for unflattening an objectencode(), which consumes a JavaScript object and returns anArrayBuffercontaining the serialized datadecode(), which consumes a nodeArrayBufferobject and returns a JavaScript object identical to the originaltoJson(), which consumes a nodeArrayBufferobject and writes the JSON representation of said object into aCBORtoJSON.jsonfile in the top directorytoText(), which consumes a nodeArrayBufferobject and writes the text representation of said object into aCBORtoTEXT.txtfile in the top directory
For toJson() and toText(), if the file is not found, a new one will be generated. Otherwise, the CBOR conversion is appended to the existing file.
All data types are supported for value, including null and undefined. Keys must be of type string and fields of type Array[string].
The below code snippet writes and then retrieves a value from the redis-server, asserting that the value is correct.
const assert = require('assert');
const createClient = require('tinycbor-redis'); //used to obtain the C++ addon constructor
const CBOR = createClient() //call the retrieved function to instantiate a cbor instance
let key = "key"
let path = ['a', 'b', 'c']
let value = true
/*
* `path` and `value` are both encoded to CBOR format internally
* the encoded results are written to the redis-server
*/
CBOR.hset(key, path, value)
/*
* the result of the `hget` operation is decoded from CBOR and converted to the JavaScript equivalent
* it is then returned to the calling program
*/
let output = CBOR.hget(key, path)
assert.deepEqual(output, value);Installation
To use tinycbor-redis, use:
yarn add tinycbor-redisOtherwise, to manually install, enter the directory and use:
yarn install8 years ago