Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-json

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-json - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# v2.1.0
* Support for key expiry
# v2.0.0

@@ -2,0 +5,0 @@ ### Breaking Changes

25

index.js

@@ -21,7 +21,17 @@ const flatten = require("flat");

* @param {Object} obj JSON object to be stored
* @param {Options} options
*
* @typedef {Object} Options
* @property {Number} expire Max time in seconds for the key to live
*/
set(key, obj) {
async set(key, obj, options = {}) {
const flattened = flatten(obj);
return this.redisClient.hmset.call(this.redisClient, key, flattened);
// Custom property to check
// if the hashset has expired
flattened._present = 1;
await this.redisClient.hmset.call(this.redisClient, key, flattened);
if (options.expire)
await this.redisClient.expire.call(this.redisClient, key, options.expire);
}

@@ -42,8 +52,11 @@

);
return unflatten(flattened);
// Remove the custom property
delete flattened._present;
return Object.keys(flattened).length ? unflatten(flattened) : undefined;
}
// async get(key) {
// }
/**
* Replace the entire hashset for the given key
*

@@ -55,3 +68,3 @@ * @param {String} key Redis key

await this.redisClient.del.call(this.redisClient, key);
this.set(key, obj);
return this.set(key, obj);
}

@@ -58,0 +71,0 @@ }

{
"name": "redis-json",
"version": "2.0.0",
"version": "2.1.0",
"description": "A wrapper library to store JSON Objects in redis-hashsets and retrieve it back as JSON objects",

@@ -52,2 +52,3 @@ "main": "index.js",

"deep-equal": "^1.0.1",
"delay": "^4.1.0",
"eslint": "^3.19.0",

@@ -54,0 +55,0 @@ "eslint-config-airbnb": "^14.1.0",

@@ -53,6 +53,7 @@ # redis-json [![Build Status](https://travis-ci.com/AkashBabu/redis-json.svg?branch=master)](https://travis-ci.com/AkashBabu/redis-json)

**set(key, jsobObject): \<Promise>**
**set(key, jsobObject, options): \<Promise>**
*key*: The redis key that the JSON object has to be stored against.
*jsonObject*: JSON obejct that needs to be stored.
*options.expire*: Max time-to-live before key expiry

@@ -59,0 +60,0 @@ if the key already exists, and is of type hashset, then the field in JSON object will get updated along with the existing data.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc