npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tinycbor-redis

v0.0.0

Published

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

Downloads

1

Readme

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 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.

    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