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

v1.1.2

Published

Built on top of Redis, this package allows for easy storage, access, and mutation of primitive and non-primitive data types.

Downloads

3

Readme

Redis Everything

npm version Stars MIT license Issues

Built on top of Redis, this package allows for easy storage, access, and mutation of primitive and non-primitive data types.

Installation

npm install redis-everything

Usage Example

For a full list of available options see https://www.npmjs.com/package/redis#options-object-properties


let options = {
  host: "localhost",
  port: 6379,
  namespace: "myDb"
}

const redis = require('redis-everything')(options)

let test = async () => {
  
  let userObj = {
    name: "Sam",
    age: 20,
    address:{
      number: 251,
      street: "6th St",
      city: "San Francisco",
      state: "CA", 
      zip: 94103
    },
    friends: [{ name: "Jake" }, { name: "Ryan" }, { name: "Andrew" }]
  }
  
  //Insert user object into Redis with id "userId"
  await redis.set("userId", userObj)
  
  //Get user's address object
  let myAddress = await redis.get(["userId", "address"])
  
  /* 
   * myAddress = {
   *   number: 251,
   *   street: "6th St",
   *   city: "San Francisco"
   *   state: "CA", 
   *   zip: 94103
   * }
   */
  
  //Get first object in friend array.
  let firstFriend = await redis.get(["userId", "friends", 0])
  
  /* 
   * firstFriend = {
   *   name: "Jake"
   * }
   */
   
   let newFriend = { name: "Matt" }
   
   //Add new friend to the friend array
   await redis.push(["userId", "friends"], newFriend)
   
   //Add new attribute to user object
   await redis.addKey(["userId", "car"], "Ford Escape")
   
   //Update user attributes
   await redis.set(["userId", "age"], 21)
   
   let newCarSpecs = {
    make: "Ford",
    model: "Escape"
   }
   await redis.set(["userId", "car"], newCarSpecs)
   
   //Remove element from an array
   await redis.remove(["userId", "friends", 2])
   
   //Remove a key 
   await redis.remove(["userId", "name"])
   
   //Get full object from redis
   userObj = await redis.get("userId")
   /*
    *  userObj = {
    *    age: 21,
    *    address:{
    *      number: 251,
    *      street: "6th St",
    *      city: "San Francisco",
    *      state: "CA", 
    *      zip: 94103
    *    },
    *    friends: [{ name: "Jake" }, { name: "Ryan" }, { name: "Matt" }],
    *    car:{
    *      make: "Ford",
    *      model: "Escape"
    *    }
    *  }
    */
   
    //Get full list of keys in namespace
    let keys = await redis.keys()
    
    /*
     *  keys = ["userId"]
     */
   
    //Remove full object from Redis
    await redis.remove("userId")
    
    //All functions also can use callbacks instead
    redis.set("myObj", { key1: "value" }, (err) => {
      if(err) throw err
      
      redis.get("myObj", (err, myObj) =>{
        if(err) throw err
        console.log("myObj is: ", myObj)
      })
      
    })
   
}

API

redis.set([baseKey, key1, ...], value, [callback])

Sets an object, array, or primitive at the given baseKey. If baseKey does not exists, then it will be created. In order to mutate an object, or array, you can use this function and specify the path of the object you would like to update.

redis.get([baseKey, key1, ...], [callback])

Gets an object, array, or primitive at the given baseKey. If more keys are provided, the object at the full path will be given.

redis.remove([baseKey, key1, ...], [callback])

Removes an object, or array element at the given path. If just the baseKey is given, the full object will be removed from Redis.

redis.addKey([baseKey, key1, ..., newKey], value, [callback])

Adds an object, array, or primitive at the given baseKey. The last key given will be the name of the new key assigned to the given value.

redis.push([baseKey, key1, ...], value1[, value2, value3, ...], [callback])

Adds an object, array or primitive at the end of the given array. The given path must lead to an array otherwise an error will be thrown.

redis.unshift([baseKey, key1, ...], value1[, value2, value3, ...], [callback])

Adds an object, array or primitive at the begining of the given array. The given path must lead to an array otherwise an error will be thrown.

redis.pop([baseKey, key1, ...], [callback])

Removes an object, array or primitive at the end of the given array. This will function will return the object that was popped. The given path must lead to an array otherwise an error will be thrown.

redis.shift([baseKey, key1, ...], [callback])

Removes an object, array or primitive at the begining of the given array. This will function will return the object that was removed. The given path must lead to an array otherwise an error will be thrown.

redis.arrayLength([baseKey, key1, ...], [callback])

Returns the number of elements in a given array. The given path must lead to an array otherwise an error will be thrown.

redis.objectKeys([baseKey, key1, ...], [callback])

Returns an array of strings, each string being a key from the given object. The given path must lead to a json object otherwise an error will be thrown.

redis.keys([callback])

Gives a list of all baseKeys in the Redis

redis.allKeys([callback])

Gives a list of all keys in the Redis, including pointers to other objects.

redis.hasKey(baseKey, [callback])

Returns true if the given baseKey exists in Redis. False otherwise.

redis.flushall([callback])

Removes all keys from Redis.