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

ioredis-rejson

v1.0.10

Published

Interface to RedisJSON on top of IORedis

Downloads

528

Readme

IORedis ReJSON

This module adds a layer of commands to interact with Redis ReJSON module on top of IORedis.

For IORedis commands please refer to IORedis repository.

This module uses ioredis and @types/ioredis as a dependencies

 

Known limitations: multi / pipeline is not supported with this module.

Disclaimer: this module is not battle tested, if you find any issue with it please open an issue or a pull request.

 

Quick Start

 

  1. Install module

    yarn add ioredis-rejson
    yarn add -D @types/ioredis

    or

    npm install --save ioredis-rejson
    npm install --save-dev @types/ioredis

     

  2. Create a client instance

import Redis from 'ioredis-rejson';

const redis = new Redis({
  host: '127.0.0.1',
  port: 16379,
});

 

  1. Interact with redis using the just created client instance
...
const main = async () => {
  // ReJSON Methods
  const res = await redis.json_set('JSONKEY', '.', { foo: 'bar' }, 'NX');
  const res2 = await redis.json_get('JSONKEY');

  console.log(res); // OK
  console.log(res2); // { foo: "bar"}

  // IORedis Methods
  const res3 = await redis.set('KEY', 'VALUE');
  const res4 = await redis.get('KEY');

  console.log(res3); // OK
  console.log(res4); // "VALUE"
}

main()

 

NOTE: ioredis-rejson serializes and deserializes data where needed to facilitate interaction, you can pass objects, arrays, strings, etc and it will be serialized as json where it needs to be, same for get requests, the returned data will be deserialized.

 

Commands

JSON_SET

await redis.json_set('KEY', 'PATH', 'DATA', '*optional* NX | XX');
Return value

String OK if executed correctly or null if the specified NX XX conditions were not met.

Time complexity

O(M+N), where M is the size of the original value (if it exists) and N is the size of the new value.

 


JSON_GET

await redis.json_get('KEY', '*optional* PATH');
Return value

Returns the parsed json data from path or null

Time complexity

O(N), where N is the size of the value.

 


JSON_MGET

await redis.json_mget(['KEY1', 'KEY2', '...'], 'PATH');
Return value

Returns the parsed json data from path or null

Time complexity

O(M*N), where M is the number of keys and N is the size of the value.

 


JSON_DEL

await redis.json_del('KEY', '*optional* PATH');
Return value

Integer, specifically the number of paths deleted (0 or 1).

Time complexity

O(N), where N is the size of the deleted value.

 


JSON_NUMINCRBY

await redis.json_numincrby('KEY', 'PATH', 'NUMBER');
Return value

Float, specifically the new value

Time complexity

O(1).

 


JSON_NUMMULTBY

await redis.json_nummultby('KEY', 'PATH', 'NUMBER');
Return value

Float, specifically the new value

Time complexity

O(1).

 


JSON_STRAPPEND

await redis.json_strappend('KEY', '*optional* PATH', 'NUMBER');
Return value

Integer, specifically the string's new length.

Time complexity

O(N), where N is the new string's length.

 


JSON_STRLEN

await redis.json_strlen('KEY', '*optional* PATH');
Return value

Integer, specifically the string's length.

Time complexity

O(1).

 


JSON_ARRAPEND

await redis.json_arrapend('KEY', 'PATH', 'DATA | [DATA]');
Return value

Integer, specifically the array's new length.

Time complexity

O(1).

 


JSON_ARRINDEX

await redis.json_arrindex(
  'KEY',
  'PATH',
  'DATA',
  '*optional* START',
  '*optional* STOP'
);
Return value

Integer, specifically the position of the scalar value in the array, or -1 if unfound.

Time complexity

O(N), where N is the array's size.

 


JSON_ARRINSERT

await redis.json_arrinsert('KEY', 'PATH', 'INDEX', 'DATA | [DATA]');
Return value

Integer, specifically the array's new size.

Time complexity

O(N), where N is the array's size.

 


JSON_ARRLEN

await redis.json_arrlen('KEY', '*optional* PATH');
Return value

Integer, specifically the array's length.

Time complexity

O(1).

 


JSON_ARRPOP

await redis.json_arrpop('KEY', '*optional* PATH', '*optional* INDEX');
Return value

The deserialized popped value

Time complexity

O(N), where N is the array's size for index other than the last element, O(1) otherwise.

 


JSON_ARRTRIM

await redis.json_arrtrim('KEY', 'PATH', 'START', 'STOP');
Return value

Integer, specifically the array's new size.

Time complexity

O(N), where N is the array's size.

 


JSON_OBJKEYS

await redis.json_objkeys('KEY', '*optional* PATH');
Return value

Array, specifically the key names in the object as strings.

Time complexity

O(N), where N is the number of keys in the object.

 


JSON_OBJLEN

await redis.json_objlen('KEY', '*optional* PATH');
Return value

Integer, specifically the number of keys in the object.

Time complexity

O(1).

 


JSON_TYPE

await redis.json_type('KEY', '*optional* PATH');
Return value

Simple String, specifically the type of value.

Time complexity

O(1).

 


JSON_FORGET

same as json_del

await redis.json_forget('KEY', '*optional* PATH');
Return value

Integer, specifically the number of paths deleted (0 or 1).

Time complexity

O(N), where N is the size of the deleted value.

 


JSON_RESP

await redis.json_resp('KEY', '*optional* PATH');
Return value

Array, specifically the JSON's RESP form as detailed.

Time complexity

O(N), where N is the size of the JSON value.