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

redis-store-json

v1.1.0

Published

Light package for easily getting and storing json object on redis database

Downloads

26

Readme

redis-store-json

:warning: i did a mistake on versionning last version is 1.1.0. I'm sorry about that

This module was at the beginning for a personal project, but I decided to publish it.

redis-store-json, is a light nodejs module that will allow to easily store, get and modify JSON object into redis database. It base on promise, so every function work with promise

Installation

npm --save install redis-store-json

You will also need the redis_nodejs package https://github.com/NodeRedis/node_redis

Getting started

Basic set-up

For more redis set-up option check https://github.com/NodeRedis/node_redis

const redisJson = require('redis-store-json'); //import the module
const redis     = require('redis');            //import redis module
const client    = redis.createClient();        //create a new redis connection

redisJson.use(client);                      //give the redis instance to redis-json-store

let testSet = {
    "testKey1" : "test",
    "testKey2" : "test2"
}
redisJson.set("REDIS_DB_KEY", testSet)  // set a new JSON key
	.then(() =>{
    	console.log("succefuly set data");
	})
	.catch(() =>{
    	console.log("error when set data");
	})

:warning: Before using any function make sure to call .use() and give your redis connection instance

Documentation

Setting and modifying data

set(redisKey, payload)

return { Promise } if resolved successfully set data, reject error

Param

| Name | Description | | -------- | ------------------------------------ | | redisKey | The key of the redis table to modify | | payload | The JSON to store |

Example
...
let testSet = {
    "testKey1" : "test",
    "testKey2" : "test2"
}
redisJson.set("REDIS_DB_KEY", testSet)  // set a new JSON key
	.then(() =>{
    	console.log("succefuly set data");
	})
	.catch(() =>{
    	console.log("error when set data");
	})

modifyValueByJsonKey(redisKey, JSONkey, value)

modify a value of a JSON object stored on a DB

Param

| Name | Description | | -------- | ------------------------------------------------ | | redisKey | The key of the redis table to modify | | JSONkey | the JSON key stored on the JSON object to modify | | value | new value to set |

Example
...
//testSet = {
//    "testKey1" : "test",
//    "testKey2" : "test2"
//}

// set the data to redis
// ...

redisJson.modifyValueByJsonKey(redisKey, "testKey1", "updatedValue" )
	.then(() =>{
    	//value modified succefuly
	})
	.catch(err => {
    	console.error(err);//error when modifing error
	})

Getting data

getJSON(databaseKey)

return if resolved a new JSON object who contain the stored database informations

Param

| Name | Description | | ----------- | --------------------------------- | | databaseKey | The key of the redis table to get |

Example
...
//testSet = {
//    "testKey1" : "test",
//    "testKey2" : "test2"
//}

// set the data to redis
// ...

redisJson.getJSON("REDIS_DB_KEY")
	.then(data =>{
    	console.log(data); // {"testKey1" : "test","testKey2" : "test2"}
	})
	.catch(err => {
    	console.log(err);
	})

getValueByJsonKey(databaseKey, JSONkey)

return if resolved return the value of the key of the JSON object store in the DB

Param

| Name | Description | | ----------- | --------------------------------- | | databaseKey | The key of the redis table to get | | JSONkey | The JSON to get data from |

Example
...
let testSet = {
    "testKey1" : "test",
    "testKey2" : "test2"
}
// set the data to redis

redisJson.getValueByJsonKey("REDIS_DB_KEY","testKey1") 
	.then(data =>{
    	console.log(data); //return "test"
	})
	.catch(err =>{
    	console.error(err);
	})

hasJSONkey(redisKey, JSONkey)

return if resolved return the value of the key of the JSON object store in the DB

Param

| Name | Description | | -------- | --------------------------------- | | redisKey | The key of the redis table to get | | JSONkey | The JSON key to check |

Example
...
let testSet = {
    "testKey1" : "test",
    "testKey2" : "test2"
}
// set the data to redis

redisJson.hasJSONkey("REDIS_DB_KEY","testKey1") 
	.then(data =>{
    	console.log(data); //return true
	})
	.catch(err =>{
    	console.error(err);
	})