# tinycbor-redis

> An expansion of node-tinycbor which provides access to select Redis commands with internal CBOR encoding/decoding

Latest version **0.0.0** (published 2017-08-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install tinycbor-redis
pnpm add tinycbor-redis
yarn add tinycbor-redis
bun add tinycbor-redis
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2017-08-23 |
| First published | 2017-08-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Samuel Patterson |
| Maintainers | samuelvpatterson |
| Keywords | tinycbor, cbor, addon |

## Links

- npm: https://www.npmjs.com/package/tinycbor-redis
- Repository: https://gitlab.com/controlenvy/lib/node-tinycbor
- npm.io page: https://npm.io/package/tinycbor-redis

## Dependencies (3)

- [nan](https://npm.io/package/nan.md) ^2.6.2
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^2.3.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^2.2.0

## Recent versions

- 0.0.0 (latest) — 2017-08-23

## README

# Node.js Addon for TinyCBOR with Redis Support

`tinycbor-redis` is a [NodeJS](http://nodejs.org) addon that combines use of [CPP_Redis](https://github.com/Cylix/cpp_redis) with the C based [tinyCBOR](https://01org.github.io/tinycbor/current/) library. With this addon, you can directly store and retrieve data from a [Redis](https://redis.io/) server connection with under-the-hood [CBOR](http://cbor.io/) 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 to
* `disconnect()`, no arguments, terminates connection to current redis server
* `hset()`, requires a string:key, Array[string]:field, any:value, writes data to server
* `hget()`,  requires a string:key, Array[string]:field, retrieves value mapped to `field`
* `hgetall()`, requires a string:key, retrieves all field-value pairs stored to `key`
* `hdel()`, requires a string:key, Array[string]:field, removes `field` and value stored to `field` from server
* `hscan()`, requires a string:key, Array[string]:field, retrieves all field-value pairs corresponding to `field`
* `del()`,  requires a string:key, removes all data stored to `key` from server
* `deleteAll()`, requires a string:key, Array[string]:field, removes all subfields of `field`, `field` included
* `parsePath()`, requires a concatenated CBOR encoded stream (e.g. x61ax61bx62c), returns array of parsed keys (e.g. ['a', 'b', 'c']), useful for unflattening an object
* `encode()`, which consumes a JavaScript object and returns an `ArrayBuffer` containing the serialized data
* `decode()`, which consumes a node `ArrayBuffer` object and returns a JavaScript object identical to the original
* `toJson()`, which consumes a node `ArrayBuffer` object and writes the JSON representation of said object into a `CBORtoJSON.json` file in the top directory
* `toText()`, which consumes a node `ArrayBuffer` object and writes the text representation of said object into a `CBORtoTEXT.txt` file 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.

```javascript
    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-redis

Otherwise, to manually install, enter the directory and use:

    yarn install

---
_Source: https://npm.io/package/tinycbor-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
