Fix issue with dot-notation on redis node

This commit is contained in:
Jan Oberhauser 2020-05-05 15:52:47 +02:00
parent 384db05483
commit adff086ea2

View file

@ -158,6 +158,33 @@ export class Redis implements INodeType {
description: 'The type of the key to get.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
operation: [
'get'
],
},
},
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Dot Notation',
name: 'dotNotation',
type: 'boolean',
default: true,
description: `By default does dot-notation get used in property names.<br />
This means that "a.b" will set the property "b" underneath "a" so { "a": { "b": value} }.<br />
If that is not intended this can be deactivated, it will then set { "a.b": value } instead.
`,
},
],
},
// ----------------------------------
// keys
// ----------------------------------
@ -292,7 +319,7 @@ export class Redis implements INodeType {
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
// Parses the given value in a number if it is one else returns a string
function getParsedValue (value: string): string | number {
function getParsedValue(value: string): string | number {
if (value.match(/^[\d\.]+$/) === null) {
// Is a string
return value;
@ -306,7 +333,7 @@ export class Redis implements INodeType {
function convertInfoToObject(stringData: string): IDataObject {
const returnData: IDataObject = {};
let key:string, value:string;
let key: string, value: string;
for (const line of stringData.split('\n')) {
if (['#', ''].includes(line.charAt(0))) {
continue;
@ -450,7 +477,15 @@ export class Redis implements INodeType {
const keyType = this.getNodeParameter('keyType', itemIndex) as string;
const value = await getValue(client, keyGet, keyType) || null;
set(item.json, propertyName, value);
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
if (options.dotNotation === false) {
item.json[propertyName] = value;
} else {
set(item.json, propertyName, value);
}
returnItems.push(item);
} else if (operation === 'keys') {
const keyPattern = this.getNodeParameter('keyPattern', itemIndex) as string;
@ -467,7 +502,7 @@ export class Redis implements INodeType {
}
for (const keyName of keys) {
set(item.json, keyName, await promises[keyName]);
item.json[keyName] = await promises[keyName];
}
returnItems.push(item);
} else if (operation === 'set') {