redis-json
Advanced tools
Comparing version 6.0.1 to 6.0.2
@@ -0,1 +1,4 @@ | ||
# v6.0.2 | ||
* minor bug fixes and performance improvements | ||
# v6.0.1 | ||
@@ -2,0 +5,0 @@ * adds function overload definition for `get` as `get(key: string): Promise<T|undefined>` |
@@ -79,3 +79,3 @@ [redis-json](../README.md) › [JSONCache](jsoncache.md) | ||
Defined in src/lib/jsonCache.ts:178 | ||
Defined in src/lib/jsonCache.ts:177 | ||
@@ -93,3 +93,3 @@ Removes/deletes all the keys in the JSON Cache, | ||
Defined in src/lib/jsonCache.ts:205 | ||
Defined in src/lib/jsonCache.ts:204 | ||
@@ -120,3 +120,3 @@ Removes the given key from Redis | ||
Defined in src/lib/jsonCache.ts:117 | ||
Defined in src/lib/jsonCache.ts:110 | ||
@@ -138,3 +138,3 @@ Retrieves the hashset from redis and | ||
Defined in src/lib/jsonCache.ts:118 | ||
Defined in src/lib/jsonCache.ts:111 | ||
@@ -156,3 +156,3 @@ **Parameters:** | ||
Defined in src/lib/jsonCache.ts:228 | ||
Defined in src/lib/jsonCache.ts:227 | ||
@@ -185,3 +185,3 @@ Increments the value of a variable in the JSON | ||
Defined in src/lib/jsonCache.ts:165 | ||
Defined in src/lib/jsonCache.ts:162 | ||
@@ -188,0 +188,0 @@ Replace the entire hashset for the given key |
@@ -428,8 +428,3 @@ import { promisify } from 'util'; | ||
const commands = yield this.getKeysToBeRemoved(key, flattened); | ||
commands.push(['hmset', this.getKey(key), flattened.data]); | ||
commands.push(['hmset', this.getTypeKey(key), flattened.typeInfo]); | ||
if (options.expire) { | ||
commands.push(['expire', this.getKey(key), options.expire]); | ||
commands.push(['expire', this.getTypeKey(key), options.expire]); | ||
} | ||
this.addSetCommands(key, flattened, commands, options.expire); | ||
yield this.execCommand(commands, options.transaction); | ||
@@ -447,5 +442,9 @@ }); | ||
// in the cache | ||
if (!data || Object.keys(data).length === 0) { | ||
if (!(data && typeInfo)) { | ||
return undefined; | ||
} | ||
const dataKeysLen = Object.keys(data).length; | ||
const typeInfoKeysLen = Object.keys(typeInfo).length; | ||
if (dataKeysLen !== typeInfoKeysLen || dataKeysLen === 0) | ||
return undefined; | ||
let result; | ||
@@ -487,5 +486,7 @@ if (fields.length > 0) { | ||
['del', this.getKey(key)], | ||
['del', this.getTypeKey(key)], | ||
]; | ||
const flattened = this.flattener.flatten(obj); | ||
this.addSetCommands(key, flattened, commands, options.expire); | ||
yield this.execCommand(commands, options.transaction); | ||
yield this.set(key, obj, options); | ||
}); | ||
@@ -586,2 +587,3 @@ } | ||
commands.push(['hdel', this.getKey(key), ...keysToBeRemoved]); | ||
commands.push(['hdel', this.getTypeKey(key), ...keysToBeRemoved]); | ||
} | ||
@@ -614,2 +616,21 @@ } | ||
} | ||
/** | ||
* Will add Set commands to the given array | ||
* This logic was separated to remove code duplication | ||
* in set & rewrite methods | ||
* | ||
* @param key Storage key | ||
* @param flattened Flattened object containing data & typeInfo | ||
* @param commands List of commands to which set commands has to be appended | ||
* @param expire Redis Key expiry | ||
*/ | ||
addSetCommands(key, flattened, commands, expire) { | ||
commands.push(['hmset', this.getKey(key), flattened.data]); | ||
commands.push(['hmset', this.getTypeKey(key), flattened.typeInfo]); | ||
if (expire) { | ||
commands.push(['expire', this.getKey(key), expire]); | ||
commands.push(['expire', this.getTypeKey(key), expire]); | ||
} | ||
return commands; | ||
} | ||
execTransactionCommands(commands, transaction) { | ||
@@ -616,0 +637,0 @@ commands.forEach(command => { |
@@ -430,8 +430,3 @@ 'use strict'; | ||
const commands = yield this.getKeysToBeRemoved(key, flattened); | ||
commands.push(['hmset', this.getKey(key), flattened.data]); | ||
commands.push(['hmset', this.getTypeKey(key), flattened.typeInfo]); | ||
if (options.expire) { | ||
commands.push(['expire', this.getKey(key), options.expire]); | ||
commands.push(['expire', this.getTypeKey(key), options.expire]); | ||
} | ||
this.addSetCommands(key, flattened, commands, options.expire); | ||
yield this.execCommand(commands, options.transaction); | ||
@@ -449,5 +444,9 @@ }); | ||
// in the cache | ||
if (!data || Object.keys(data).length === 0) { | ||
if (!(data && typeInfo)) { | ||
return undefined; | ||
} | ||
const dataKeysLen = Object.keys(data).length; | ||
const typeInfoKeysLen = Object.keys(typeInfo).length; | ||
if (dataKeysLen !== typeInfoKeysLen || dataKeysLen === 0) | ||
return undefined; | ||
let result; | ||
@@ -489,5 +488,7 @@ if (fields.length > 0) { | ||
['del', this.getKey(key)], | ||
['del', this.getTypeKey(key)], | ||
]; | ||
const flattened = this.flattener.flatten(obj); | ||
this.addSetCommands(key, flattened, commands, options.expire); | ||
yield this.execCommand(commands, options.transaction); | ||
yield this.set(key, obj, options); | ||
}); | ||
@@ -588,2 +589,3 @@ } | ||
commands.push(['hdel', this.getKey(key), ...keysToBeRemoved]); | ||
commands.push(['hdel', this.getTypeKey(key), ...keysToBeRemoved]); | ||
} | ||
@@ -616,2 +618,21 @@ } | ||
} | ||
/** | ||
* Will add Set commands to the given array | ||
* This logic was separated to remove code duplication | ||
* in set & rewrite methods | ||
* | ||
* @param key Storage key | ||
* @param flattened Flattened object containing data & typeInfo | ||
* @param commands List of commands to which set commands has to be appended | ||
* @param expire Redis Key expiry | ||
*/ | ||
addSetCommands(key, flattened, commands, expire) { | ||
commands.push(['hmset', this.getKey(key), flattened.data]); | ||
commands.push(['hmset', this.getTypeKey(key), flattened.typeInfo]); | ||
if (expire) { | ||
commands.push(['expire', this.getKey(key), expire]); | ||
commands.push(['expire', this.getTypeKey(key), expire]); | ||
} | ||
return commands; | ||
} | ||
execTransactionCommands(commands, transaction) { | ||
@@ -618,0 +639,0 @@ commands.forEach(command => { |
{ | ||
"name": "redis-json", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"description": "A wrapper library to store JSON Objects in redis-hashsets and retrieve it back as JSON objects", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -132,2 +132,13 @@ import type { RecursivePartial } from '../interfaces'; | ||
private getTypeKey; | ||
/** | ||
* Will add Set commands to the given array | ||
* This logic was separated to remove code duplication | ||
* in set & rewrite methods | ||
* | ||
* @param key Storage key | ||
* @param flattened Flattened object containing data & typeInfo | ||
* @param commands List of commands to which set commands has to be appended | ||
* @param expire Redis Key expiry | ||
*/ | ||
private addSetCommands; | ||
private execTransactionCommands; | ||
@@ -134,0 +145,0 @@ private execCommand; |
81415
1641