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

rejects

v0.6.2

Published

Enable easy object storage in Redis using native types.

Downloads

3

Readme

Redis Objects

Simple abstractions for storing complex JSON data in Redis. Supports storage of complex objects and arrays.

Example

const Redis = require('ioredis');
const { Rejects } = require('rejects');

const r = new Redis();
const s = new Rejects(r);

s.set('some key', {
  id: 'some id',
  array: [
    'array',
    'of',
    'primitives',
    {
      and: 'an',
      object: 'too',
    },
  ],
  data: {
    complex: 'nested',
    data: 'here',
    with: [
      'an',
      'array',
    ],
  },
});

Nested data can be directly accessed and modified by concatentating properties together with a .. For example:

const data = await s.get('some key'); // { id: 'some id', ... }
const with = await s.get('some key.data.with', { type: 'arr' }); // ['an', 'array']
const update = await s.set('some key.data.with', ['new', 'array']);
const added = await s.upsert('some key.data.with', ['element']);

Note that the type must be explicitly set to arr when directly accessing an array. Upserts are faster than sets, as they do not have to clear out the existing data before adding new data.

References to other data can be created:

const { Reference } = require('rejects');

await s.set('some other key', {
  value: 'hello world',
});

await s.set('some key', {
  id: 'an id',
  reference: new Reference('some other key.value'),
});

const data = await s.get('some key'); // { id: 'an id', reference: 'hello world' }

References can be created within arrays to create arrays of references. The Reference constructor takes a second parameter of either obj or arr to differentiate between references to arrays and objects (default to obj).

Caveats

  • Array entries are not actually stored as arrays, and as such order will not be preserved when fetching. It also follows that:
  • Array entries can never be overridden unless you delete the entire entry and re-add the elements.

Reference

default

  • constructor(redis: Redis) - make a new instance and give it an ioredis client
  • get(key: string, { full = true, type = 'obj', depth = -1 }) - get a complex object. Valid type values are arr and obj depending on the anticipated data type of the fetched data. If full is true, will resolve all references to nested data. If full is false, will set the property to a string of the form ref:<type>:<key> where type is arr or obj, and key points to the Redis key where the data is stored. Setting a depth option of 0 or greater will ensure recursion to only the specified depth.
  • set(key: string, data: any) - set complex data; will overwrite and remove existing data that is changed or removed in the new data.
  • upsert(key: string, data: any) - set complex data; will overwrite but not remove existing data.
  • delete(key: string) - delete all complex data at a given key.
  • keys(key: string) - get the keys of the object at key.
  • size(key: string) - get the size of the object at key.
  • incr(key: string, count = 1) - increment the value at key by count.