Skip to content

Latest commit

 

History

History
109 lines (100 loc) · 2.93 KB

README.md

File metadata and controls

109 lines (100 loc) · 2.93 KB
redistojson
# Redis-to-JSON-converter Converts Redis data to JSON representation

For those seeking a means to convert redis "string" data to JSON object for easy parsing.

Special Thanks to my friend, Augustine Best and also Jerry for their amazing contributions and My boss Okoye Emmanuel for tasking us with the solution to the pending redis problem. it's good to work with great minds @geneystechhub

How to use

step 1: Install reformat-date

npm install redistojson --save

step 2: Require the package in your project

const redistojson = require('redistojson');

step 3: Pass in the redis data you wish to convert as an argument
-for example
case 1: having a list of persons data

const redisData = "Persons,[name,adegoke,address,gentlemen in ikorodu,age,90,sex,masculine,pet,Bethy,wife,Mai,school,],[name,Augustine Best,address,Enugu,age,32,sex,male,pet,Cowboy,wife,Juin,school,FUTO],[name,Femi,address,Surulere,age,45,sex,male,pet,Cat,wife,Queen,school,UNILAG],[name,Peter,address,Ikeja,age,23,sex,male,pet,Dog,wife,Angela,school,OAU],[name,Betty,address,Porharcourt,age,21,sex,female,pet,Elephant,wife,princess,school,UNIBEN],[name,Jessie,address,Toronto,age,49,sex,male,pet,Goat,wife,Stephanie,school,Harvard]";

console.log(redistojson(redisData));

// result 
{
  Persons: [
    {
      name: 'adegoke',
      address: 'gentlemen in ikorodu',
      age: '90',
      sex: 'masculine',
      pet: 'Bethy',
      wife: 'Mai',
      school: ''
    },
    {
      name: 'Augustine Best',
      address: 'Enugu',
      age: '32',
      sex: 'male',
      pet: 'Cowboy',
      wife: 'Juin',
      school: 'FUTO'
    },
    {
      name: 'Femi',
      address: 'Surulere',
      age: '45',
      sex: 'male',
      pet: 'Cat',
      wife: 'Queen',
      school: 'UNILAG'
    },
    {
      name: 'Peter',
      address: 'Ikeja',
      age: '23',
      sex: 'male',
      pet: 'Dog',
      wife: 'Angela',
      school: 'OAU'
    },
    {
      name: 'Betty',
      address: 'Porharcourt',
      age: '21',
      sex: 'female',
      pet: 'Elephant',
      wife: 'princess',
      school: 'UNIBEN'
    },
    {
      name: 'Jessie',
      address: 'Toronto',
      age: '49',
      sex: 'male',
      pet: 'Goat',
      wife: 'Stephanie',
      school: 'Harvard'
    }
  ]
}

case 2: having an object of a data

const redisData = "Person,name,adegoke,address,gentlemen in ikorodu,age,90,sex,mascufeline,pet,Bethy,wife,Mai,school,";

console.log(redistojson(redisData)); 

// result
{
  Person: {
    name: 'adegoke',
    address: 'gentlemen in ikorodu',
    age: '90',
    sex: 'mascufeline',
    pet: 'Bethy',
    wife: 'Mai',
    school: ''
  }
}

All the best